baethon / kex Goto Github PK
View Code? Open in Web Editor NEWORM-less for Knex
License: MIT License
ORM-less for Knex
License: MIT License
The Model
object should proxy following methods directly to the instance of QueryBuilder
:
where()
insert()
update()
find()
and findOrFail()
When passing a callback to some of knex methods (e.g. whereExists()
) the function is bound to the query builder of the model. It might pollute the query with models global query scopes.
The only exception is the query constrant method (where()
, andWhere()
, orWhere()
etc).
The idea to consider - should the plugin process be split into two steps:
configure()
- alter options of the Model (before its initialization)extend()
- extend the instance of a newly created objectI can imagine a situation where a plugin wants to set up/alter some of the option values, yet there's no need to extend the model instance.
Would it be useful?
const User = kex.createModel('User', {
relations: {
messages: new HasMany('Message')
}
})
This would generate the getMessages(id)
method which generates a query to the Message
model with corresponding WHERE statement.
Following call:
User.updateOne(1, { name: 'Jon' })
would be a shorthand for:
User.query()
.where('$primaryKey', 1)
.update({ name: 'Jon' })
It would be nice to have a whereHas
method which checks if the model has given relation.
await User.query()
.whereHas('Message')
would result in the following query:
select * from users where exists (
select * from messages where messages.user_id = users.id
)
Following call:
User.deleteOne(1)
would be a shorthand for:
User.query()
.where('$primaryKey', 1)
.delete()
Now, every plugin needs to monkey-patch some of the methods (e.g. then()
, update()
etc). Would be great if the QueryBuilder could emit events before/after some particular actions.
Bonus points - the listeners are able to modify the input data.
In Laravel one can cast attributes from (or to) a given type. Something similar would be useful for Kex.
Example case - MySQL with no support for boolean type.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.