Detalhes do pacote

@knorm/relations

knorm8.2kMIT4.0.0

Relations plugin for @knorm/knorm

knorm, plugin, relations, joins

readme (leia-me)

@knorm/relations

npm version dependency status

Knorm plugin that adds ability to fetch data from multiple tables via SQL joins.

Documentation

Visit the documentation site.

changelog (log de mudanças)

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

4.0.0 (2020-04-14)

Note: Version bump only for package @knorm/relations

4.0.0-alpha.1 (2020-04-14)

Bug Fixes

  • update @knorm/knorm's peer dependency version (c489b79)
  • update @knorm/postgres's peer dependency version (5c56ddc)

4.0.0-alpha.0 (2020-04-14)

Features

  • add typescript type definitions (2a97c00)

BREAKING CHANGES

  • Replaced default exports with named exports. This affects the factory functions that are the main package exports and applies to @knorm/knorm and ALL plugins.

Instead of:

const knorm = require('@knorm/knorm');
const knormPostgres = require('@knorm/postgres');

const { Knorm } = knorm;
const { KnormPostgres } = knormPostgres;

Do:

const { knorm, Knorm } = require('@knorm/knorm');
const { knormPostgres, KnormPostgres } = require('@knorm/postgres');

3.0.0 (2020-02-07)

Bug Fixes

  • Query: refactor handling of references (caf792d)
  • support joining with children models (6a544bc)
  • throw an error if an on field (as a string) doesn't exist (2f575bc)

Features

BREAKING CHANGES

  • Referencing a field on the parent join's model using a string is no longer supported; it was only supported due to a bug. Instead, use a Field instance:
Model.fields = { id: 'integer' };

class User extends Model {}
class Image extends Model {}

Image.fields = {
  userId: { type: 'integer', references: User.fields.id }
};

Image.fetch({
  // wrong:
  // join: User.query.on('userId')
  // correct:
  join: User.query.on(Image.fields.userId)
});

However, fields on the same model can still be referenced by their string field-name:

User.fetch({ join: Image.query.on('userId') });

2.0.0 (2019-02-03)

Bug Fixes

  • Query: parse empty left-joined rows as empty array (b67ed9a), closes #8
  • Query: use JOIN clause for join query option (b320cc4)

chore

Features

  • Query: support fields: false on joined queries (a3efbf3)

BREAKING CHANGES

  • This plugin now peer-depends on @knorm/knorm v2
  • Query: Empty rows in left-joined data are now returned as an empty array instead of null. However, if the first option is configured on the joined query, the empty row is still returned as null. This matches other Query methods (fetch etc).

1.3.1 (2018-11-15)

Bug Fixes

  • move reference-check error to preparation phase (86954b6)

1.3.0 (2018-09-30)

Features

  • support support multiple references (9319531)
class Foo extends Model {}
Foo.fields = { id: 'integer' };

class Bar extends Model {}
Bar.fields = { id: 'integer' };

class Quux extends Model {}
Foo.fields = {
  refId: {
    type: 'integer',
    // multiple references can be defined as an array
    // or as a function that returns an array
    references: [Foo.fields.id, Bar.fields.id]
  }
};

// these fetches would now supported:
Quux.fetch({ join: Foo });
Quux.fetch({ join: Bar });
Foo.fetch({ join: Quux });
Bar.fetch({ join: Quux });

1.2.3 (2018-09-19)

Bug Fixes

  • fix handling of first on joined queries (165ddb9)

1.2.2 (2018-09-19)

Bug Fixes

  • maintain sort order defined with orderBy (89a3343)

1.2.1 (2018-08-13)

1.2.0 (2018-08-09)

Bug Fixes

  • on does not support multiple fields (80788d8)
  • allow replacing existing fields with joined data (15243b9)

Features

  • support on as a field instance (27a1bc1)
  • support self-referencing models (312f106)

1.1.4 (2018-07-06)

1.1.3 (2018-07-06)

Bug Fixes

  • ensure joined data is null if the row is empty (3f0143b)

1.1.2 (2018-07-06)

Bug Fixes

  • add a property to indicate joined queries (065e272)

1.1.1 (2018-06-27)

Bug Fixes

  • delete reference functions when a field is removed (342aa93)

1.1.0 (2018-06-27)

Features

  • support references as a function (b31b046)

1.0.0 (2018-06-27)

Bug Fixes

  • delete model references when there are no field references (2f4524c)
  • do not overwrite Field from parent Model (e995bf6)
  • include referenced model as null when no rows are matched (29b97e8)
  • require primary or unique fields for joins (8de149c)

Features

  • add plugin name (bc53386)
  • allow disabling check for unique field (7d6db8a)
  • remove field references when a field is removed (ef297c2)