Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] DAO improvements #346

Merged
merged 17 commits into from
Jun 23, 2015
Merged

[refactor] DAO improvements #346

merged 17 commits into from
Jun 23, 2015

Conversation

thibaultcha
Copy link
Member

Fix #103: DAO assuming id and created_at were part of every entity and removing written queries for CRUD operations for simpler plugins DAO creation (#312).

Changes
  • DAOs don't require written queries anymore, see query_builder.lua.
  • Schema changes:
    • dao_insert specifies a field is generated by the DAO itself. For ex, if using Cassandra, it'll be a uuid, or it can be an int for another DB.
  • find_one() renamed find_by_primary_key() which still takes a table and that table should contain every key part of the entity's primary key.
  • Schemas are now more descriptive. Fields are in a fields table and introducing primary_key, indexes and clustering_key (the latest only for Cassandra) that are useful for the query_builder to know when to ALLOW FILTERING or not.
  • queryable = true on a schema field means to the Cassandra DAO that this field is indexed by Cassandra.
  • A new schema property: on_insert() to be executed when inserting an entity.
Todo
  • Polishing. Method names, code efficiency.
  • Documentation.
  • Testing: more tests for edgecases.
  • Since we are not necessarily preparing on start, find another way to check the connection to cassandra.

@thibaultcha thibaultcha added the pr/wip A work in progress PR opened to receive feedback label Jun 18, 2015
@thibaultcha thibaultcha mentioned this pull request Jun 19, 2015
@thibaultcha thibaultcha added NEEDS REVIEW and removed pr/wip A work in progress PR opened to receive feedback labels Jun 22, 2015
@thibaultcha
Copy link
Member Author

Needs reviewing, testing, a bit of squashing otherwise done feature-wise.

@thibaultcha thibaultcha added pr/ready (but hold merge) No more concerns, but do not merge yet (probably a conflict of interest with another PR or release) and removed NEEDS REVIEW labels Jun 23, 2015
- New property on a schema field: `dao_insert_value` to specify this
  value will be set by the DAO. Any previously set value will be
  overriden. Ignored on update operation.
- This property calls a function expected as being part of the `options`
  table given to `validate`. This function will take the field
  definition as a parameter.
- No more constants for schema types for several reasons: lua types
  aren't constants, so string, number, or id are now all on the same
  level: plain strings. It should be considered a **litteral**. It's
  also painful to import constants everywhere, especially in plugins.
  Not much benefits from making those constants.

Partially fixes #103
Primary key and indexed columns are now stored in the schema and used by
the query builder to build valid WHERE fragment for queries.
- cassandra_spec.lua doesn't have keyauth and ratelimiting tests too.
  Those are now living in `plugins/`
- cassandra_spec.lua now focuses on the Base DAO behaviour, instead of
  the entities schemas and their validation (that is
  `entities_schema_spec.lua`'s role)
- DAOs `_queries` is renamed `queries`
- `query_builder.lua` returns a boolean indicating whether or not ALLOW
  FILTERING was added to the query
- Factory checks if the DB is accessible even if there is no queries to
  prepare
- rename `cassandra_spec` to `base_dao_spec`
By doing a PUT request to the API, one can now omit a field. If that
field is omitted and if the schema still validates, the value will be
set to null in the DB.
thibaultcha added a commit that referenced this pull request Jun 23, 2015
@thibaultcha thibaultcha merged commit 42e8b6c into master Jun 23, 2015
@thibaultcha thibaultcha deleted the refactor/dao branch June 23, 2015 20:19
ctranxuan pushed a commit to streamdataio/kong that referenced this pull request Aug 25, 2015
[refactor] DAO improvements

Former-commit-id: 817748a13550493e7ec0a2dfeb8aa605cd99ef14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/ready (but hold merge) No more concerns, but do not merge yet (probably a conflict of interest with another PR or release)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant