You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It was just an initial version to quickly replace Sequelize methods with raw queries and should be refactored to provide more power and dry it.
The builder should provide a fluent interface for building, escaping and executing raw queries through Sequelize.query().
A very basic draft of the Query Builder could look like the following.
classQueryBuilder{select(columns='*'){//}from(table){//}as(alias){//}where(column,operator,value){//}whereBetween(column,from,to){//}whereNotBetween(column,from,to){//}whereLike(column,value){//}whereNotLike(column,value){//}whereIn(column,value){//}whereNotIn(column,value){//}whereNull(column){//}whereNotNull(column){//}whereKeyValuePairs(conditions){// Remove - Make it possible to pass in objects to .where()}whereStruct(conditions){// Remove - Make it possible to pass in objects to .where()}whereRaw(query){// Remove - This is currently only needed because of the prototype state of the builder}orWhere(column,value,operator='='){//}andWhere(column,value,operator='='){//}groupBy(column){//}orderBy(column,direction){//}skip(value){//}take(value){//}all(){//}first(){//}raw(query){//}}
The down side of this approach is that everything is in one class and not clearly separated. A better approach is to have a basic builder that has many Concerns that will provide the underlying functionality of select, where, group and whatever else is needed.
Concerns would look like the following and are easy to extend.
This needs be part of core as other plugins should make use of it instead of using the Sequelize methods directly which causes massive overhead compared to raw queries.
It's very easy to kick a node into a fork by corrupting the database with a bunch of resource hungry queries to the blocks table by using Sequelize methods instead of raw queries.
Will work on that tomorrow or friday, should be a quick one.
I recently added https://github.com/fix/ark-core/blob/master/packages/core-database-sequelize/lib/query-builder.js to have a clean and fluent way of building and executing raw queries.
It was just an initial version to quickly replace Sequelize methods with raw queries and should be refactored to provide more power and dry it.
The builder should provide a fluent interface for building, escaping and executing raw queries through
Sequelize.query()
.A very basic draft of the Query Builder could look like the following.
The down side of this approach is that everything is in one class and not clearly separated. A better approach is to have a basic builder that has many
Concerns
that will provide the underlying functionality ofselect
,where
,group
and whatever else is needed.Concerns would look like the following and are easy to extend.
This way we will be able to build concerns for each part of a query and provide a fluent interface like the following.
The text was updated successfully, but these errors were encountered: