vasern / vasern

Vasern is a fast, lightweight and open source data storage for React Native

Home Page:https://vasern.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Relationship table

chococrypto opened this issue · comments

Can we make a pivot table? I didn't find it in the documentation.

  • If that's the case, how can we do it ?

here is an exemple :

users
    id - integer
    name - string

roles
    id - integer
    name - string

role_user
    user_id - integer
    role_id - integer
    text - string

Hey @di1606,

I don't understand the term "pivot table". Can you explain it?

(Look to me like the role_user is kind of a relationship table for users and roles?)

yes, I'm referring to a relationship tablet

Have you tried using the reference type data type?

For example:

Note that the document/table will generate id automatically, [so no id field]

(https://vasern.github.io/docs/write-schema-setup-vasern#write-schema)

users
    name - string

roles
    name - string

role_user
    user - #users
    role - #role
    text - string

Then with the Vasern instance, you can you list

For example

const db = new Vasern(...);
let data = db.list("role_user");

I haven't tested the code but it should be. Let me know how you go

Thank you. It works.