Git Product home page Git Product logo

kex's People

Contributors

dependabot[bot] avatar radmen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

hharzer

kex's Issues

Add query proxy methods

The Model object should proxy following methods directly to the instance of QueryBuilder:

  • where()
  • custom scopes
  • insert()
  • update()
  • find() and findOrFail()

Inner queries should not be bound to models query builder

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).

Split plugins initialization process

The idea to consider - should the plugin process be split into two steps:

  1. configure() - alter options of the Model (before its initialization)
  2. extend() - extend the instance of a newly created object

I 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?

Add `get${relationName}` methods to model

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.

Add 'updateOne()' method

Following call:

User.updateOne(1, { name: 'Jon' })

would be a shorthand for:

User.query()
  .where('$primaryKey', 1)
  .update({ name: 'Jon' })

Add whereHas for checking the relations

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
)

Add 'deleteOne' method

Following call:

User.deleteOne(1)

would be a shorthand for:

User.query()
  .where('$primaryKey', 1)
  .delete()

Better events emmiter

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.

attributes casting

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.