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

[PROPOSAL] Feed primary key field with sequence.nextval and foreign key with sequence.currval #42

Open
youen opened this issue Sep 27, 2021 · 0 comments

Comments

@youen
Copy link
Collaborator

youen commented Sep 27, 2021

Context

We have to insert the jsonobject in a table film

{
  "film_id": 452
  "title" :  "The Matrix"
   "year": 1999
}

Problem

During a dataset insert primary key have to be unique to avoid conflict with existing values. Also sequences have to be updated upper than the maximum primary key inserted to avoid future conflict.

Solution

Add sequence information in table.yaml and use it during lino push insert process.

version: v1
tables:
  - name: film
    keys:
      - film_id
    sequence :
      film_id:  sequence_film_id

If the film_id is omitted, lino use the value of sequence_film_id.nextval to feed the primary_key.

Relation

If the primary key is a part of a relation

  - name: film_film_category
    parent:
        name: film
        keys:
          - film_id
    child:
        name: film_category
        keys:
          - film_id

inserting the following JSON object

{
  "title" :  "The Matrix",
   "year": 1999,
   "film_film_category" : [
      {
         "category_id": 151
      },
      {
         "category_id": 452
      },
   ]
}

will produce the sql statements

insert into film (film_id, title, year)
values (sequence_film_id.nextval, 'The Matrix', 1999);
insert into film_category (film_id, category_id)
values (sequence_film_id.currval, 151 );
insert into film_category (film_id, category_id)
values (sequence_film_id.currval, 452 );
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