Redux Orm Versions Save

NOT MAINTAINED – A small, simple and immutable ORM to manage relational data in your Redux store.

v0.14.0-rc.1

5 years ago
  • Fixed orm.<Model> selectors only returning array elements for existing IDs (when passing an ID array):
const publishers = createSelector(orm.Publisher);
publishers(orm.getEmptyState(), [1, 2, 3]); // before: []
publishers(orm.getEmptyState(), [1, 2, 3]); // after: [null, null, null]

This allows you to know which of the publishers exist and which don't.

v0.14.0-rc.0

5 years ago

Easy-to-use selector API!

Breaking changes:

  • The state slice selector is no longer used in createSelector. Pass it to the ORM constructor instead:
-const someSelector = createSelector(orm, state => state.orm, …);
+const someSelector = createSelector(orm, …);
-const orm = new ORM();
+const orm = new ORM({
+    stateSelector: state => state.orm,
+});

New features:

  • Pass a single primary key, and array of primary keys or nothing as an argument:
const movies = createSelector(orm.Movie);
movies(state);            // ref array of all movies
movies(state, 1);         // ref of movie with ID 1
movies(state, [1, 2, 3]); // ref array of movies with ID 1, 2 and 3
  • Map models to their fields:
const moviePublisher = createSelector(orm.Movie.publisher);
moviePublisher(state);            // ref array of each movie's publisher
moviePublisher(state, 1);         // ref of the first movie's publisher
moviePublisher(state, [1, 2, 3]); // publisher ref array of each of the movies with ID 1, 2 and 3
  • This works in a chained way as well:
const coverBookAuthors = createSelector(orm.Cover.book.authors);
// If the cover or its book don't exist, null is returned:
coverBookAuthors(orm.getEmptyState());            // []
coverBookAuthors(orm.getEmptyState(), 1);         // null
coverBookAuthors(orm.getEmptyState(), [1, 2, 3]); // [null, null, null]
  • Map selectors to model collections:
const bookAuthors = createSelector(orm.Book.authors);
const genreAuthors = createSelector(orm.Genre.books.map(bookAuthors));

The following would work as well and is equivalent:

const genreAuthors = createSelector(orm.Genre.books.map(orm.Book.authors));
  • With a custom result function:
const avg = arr => arr.reduce((a, b) => a + b, 0) / arr.length;
const publisherAverageRating = createSelector(
    orm.Publisher.movies.map(orm.Movie.rating),
    ratings => ratings && (ratings.length ? avg(ratings) : 'no movies')
);
  • Pass your ORM instance at any position of createSelector and get a session at the corresponding position in the result function's argument list:
const someSelector = createSelector(
    [ a,  b,     orm,  d], // a, b and d being selectors
    (_a, _b, session, _d) => session.User.count()
);

Caveats

  • You need to pass at least one selector beginning with orm to createSelector() as a replacement for passing the previous state selector function.
  • You need to handle different values of the primary key argument yourself if you want to support them:
const publisherAverageRating = createSelector(
    orm.Publisher.movies.map(orm.Movie.rating),
    (state, idArg) => idArg,
    (ratingsArg, idArg) => {
        if (typeof idArg === 'undefined' || Array.isArray(idArg)) {
            // only state was passed, or an array of IDs
            return ratingsArg.map(
                ratings => ratings && ratings.length ? avg(ratings) : 'no movies'
            );
        }
        // single publisher ID was passed
        return ratingsArg && (ratingsArg.length ? avg(ratingsArg) : 'no movies');
    }
);

v0.13.3

5 years ago
  • Prevent caching selectors if individual records accessed via index have changed. (#255, 02edce9fcad192613e799b68f2d2864564fc0313)
  • Also filter by non-PK attributes when user specifies a PK in filter object. (69a87f84d20ab7d84cb677a514c3a0d328faee9d)
  • Replace usage of lodash/mapValues by ES8 Object.entries.reduce.

v0.13.2

5 years ago

Optimized full bundles using babel-plugin-lodash and lodash-webpack-plugin:

  • dist/redux-orm.min.js decreased from 67.7 kB to 48.5 kB.
  • Gzipped size decreased from 18.5 kB to 13.1 kB.

v0.13.1

5 years ago
  • Don't filter needlessly after applying foreign key indexes. Prevents applying object-based filters again after already fully satisfying their conditions using indexes. (41ece841c2c4b35a880f84c9c985ede6c2904abb)
  • Remove attributes already looked up via index from filter clauses. After applying indexes, if additional filtering needs to occur, strip away the indexed columns from the filter object. (278ff6f7d4c60880822f3cfbb11a21b2222529c1)

Removed tests, coverage reports and other unneeded files from NPM package builds. This decreased our NPM package size to around 700 kB.

v0.13.0

5 years ago
  • Automatically index foreign keys. Queries will be fulfilled by using foreign key indexes if possible. Only works for direct FK relationships. For instance, book.authors will be optimized if the Author model has a fk({ to: 'Book', 'relatedName': 'authors' }) field. (#250, b9c16359f018dacfaaea8b5450693eea3263ffe9)

This release should be non-breaking, however it does slightly decrease performance of writes. Many-to-many queries (e.g. child.parents) are also less performant, but in theory it is now possible to optimize them by an order of magnitude (similar to SQL joins).

v0.12.4

5 years ago
  • Fixed a bug with memoization when specifying a custom mapName using Model.options. (0fb2aca3a46c7fd653bf3f0d9c8c4f937b745e7c)
  • Optimized memoization by not scanning entire tables for equality but relying on the propagated table identity instead. (0fb2aca3a46c7fd653bf3f0d9c8c4f937b745e7c)
  • Optimized model initialization by using Object.keys() instead of Object.entries(). (e371ac7161a541be41bfdaf22cd4689f1c486349)

v0.12.3

5 years ago
  • Updated dependencies, most notably Babel v7.
  • Set sideEffects: false in package.json for tree-shaking.
  • Replaced some internal usage of lodash by ES6 methods.

v0.12.2

5 years ago

Thanks to @Chris-Congenica and @abilicz for improving Redux-ORM's user experience!

  • Fixed self-referencing many-to-many relationships. They previously caused errors during initialization. (#226)
  • Throw error when user attempts to register a model class without a modelName set. (#231)
  • Throw error when user attempts to interact with the database without a session. (#237)
  • Fixed tests not running on Windows. (abe87236b4c2755afd8946b70cb199c5aece50b5)
  • Drastically increased test coverage and split up tests to make them easier to digest. (#220, 294d5f2a940499c80b613069dd955bb779926659)
  • Removed unused methods from Model. (f9efb8b2267a674dfea684c196ed13a665b75cdd)

v0.12.1

5 years ago
  • Our exported ES module in es/ (pkg.module) is now ES5 compatible. (#216, #221)
  • You can supply an as option to foreign key fields (fk()) to have Redux-ORM create a separate field for their accessors so as to not override foreign key references (#219):
class Movie extends Model {};
Movie.fields = {
    publisherId: fk({
        to: 'Publisher',
        as: 'publisher',
        relatedName: 'movies',
    }),
};

Publisher.create({ id: 123 });
const movie = Movie.create({ publisherId: 123 });

movie.publisherId // 123
movie.publisher.id === movie.publisherId // true