Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to use Objectionjs Graph Upsert for the create method #34

Closed
NotAmaan opened this issue Sep 10, 2018 · 0 comments
Closed

Add ability to use Objectionjs Graph Upsert for the create method #34

NotAmaan opened this issue Sep 10, 2018 · 0 comments
Assignees

Comments

@NotAmaan
Copy link
Collaborator

The graphUpsert offered by objection.js can also be used to insert data. It offers more flexibility when creating multiple records or relationships.

Example use-case:

const data = [{
  id: 'movie-one',
  name: 'Movie One',
}, {
  id: 'movie-two',
  name: 'Movie Two'
}];

A movie with the id movie-two already exists.

Create request:
app.service('movies').create(data)

Response if using insert graph:
Error: id provided has already been used

Response if using upsert graph:

[{
  id: 'movie-one',
  name: 'Movie One',
  createdAt: '2018-09-10T15:03:54.929Z',
  updatedAt: '2018-09-10T15:03:54.930Z'
}, {
  id: 'movie-two',
  name: 'Movie Two',
  updatedAt: '2018-09-10T15:03:54.940Z'
}]

This is just one of the many use-cases as it can also be used for relationships.

Suggested API:
A new option called createUseUpsertGraph

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant