OpenRecord v2.0.0 Release Notes

Release Date: 2018-04-18 // almost 6 years ago
  • ๐Ÿ”– Version 2.0 - whats new?

    Bulk loading

    Relations got rewritten with optional bulk loading:

    const user = await User.limit(3)const posts = await Promise.all(users.map(user =\> user.posts))
    

    ๐Ÿ‘€ will only execute 2 queries! To disable bulk loading see bulkFetch.
    ๐Ÿ‘ However, in this case it's better to use const user = await User.include('posts').limit(3)

    Faster preloading

    include was rewritten to load relations in parallel, if possible (SQL only!)

    const users = await User.find(1).include('posts')/\* will execute `SELECT * FROM users WHERE id=1` and `SELECT * FROM posts WHERE user_id = 1` in parallel\*/
    

    In V1 the above example would have loaded the data in series.

    Of course this is only possible if the conditions for the first query will contain all information needed to execute the second query!

    Model autoload (SQL only)

    Similar to autoloading model attributes, it's now possible to autoload models.

    const Store = require('openrecord/store/sqlite3')const store = new Store({ file: './my-posts-db.sqlite3', autoLoad: true // enable autoload})store.ready(async () =\> { const post = await store.Model('Post').find(1) // Post model is automatically available, if a table `posts` is defined in the sqlite3 database before.console.log(post) })
    

    Classes

    Defining a model via ES6 classes is now possible

    class User extends Store.BaseModel{ fullName(){ return `${this.first\_name} ${this.last\_name}` } }
    

    GraphQL

    ๐Ÿ‘Œ Support for GraphQL with automatic relation loading and more.

    Webpack

    It's now possible to bundle your store via webpack (Version 3 and 4)
    ๐Ÿ”Œ There is also a Webpack Plugin to cache your data structure inside your bundle. (Faster startup for serverless apps)

    Custom operators

    ๐Ÿ”Œ It's now possible to define custom operators and use the whole power of knex

    // the new operator is called `regexp`store.addOperator('regexp', function(field, value, query, condition){ query.where(field, '~', value.toString().replace(/(^\/|\/$)/g, '')) // naiv conversion of js regexp to postgres regexp!})// and it will be appended to the `string` typestore.appendOperator('string', 'regexp')
    

    Query via:

    const user = await User.where({login\_regexp: /open.\*/})
    

    Everything Promise!

    ๐Ÿ“ฆ The whole core was rewritten to use Promises instead of async.

    ๐Ÿ“„ Docs

    ๐Ÿ“„ Docs are now available via https://openrecord.js.org

    ๐Ÿ’ฅ Breaking Changes to V1

    • ๐Ÿ”Œ plugins and models store config does not take paths anymore. To get the old behavior back, use the automatic model loading plugin
    • ๐Ÿ”Œ paranoid plugin scope to get all records was renamed to withDeleted instead of with_deleted
    • 0๏ธโƒฃ join() does an inner join by default (instead of a left join)
    • Failed validations will now throw an error! Thereforesave, delete, create,... won't return success anymore. Instead it will return the record on success
    • ๐Ÿšš Hooks must return a promise or undefined. The done callback was removed.
    • create, save, destroy, ... won't take callbacks any more. use e.g. record.save().then(callback)
    • Relation records wont be saved anymore. except you set autoSave to true (store or per relation)
    • Accessing a relation via e.g. user.posts will return a then-able object. To access loaded data directly use user._posts (Will return null if not loaded)
    • limit(1) does not return a single record anymore. Use first() or singleRecord() instead
    • logger option on store is no longer available. openrecord now uses the debug module
    • โฌ‡๏ธ Drop support for NodeJS lower version 4