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

[rfc] static indexes #150

Open
cyjake opened this issue Jul 28, 2021 · 0 comments
Open

[rfc] static indexes #150

cyjake opened this issue Jul 28, 2021 · 0 comments

Comments

@cyjake
Copy link
Owner

cyjake commented Jul 28, 2021

Model needs someway to declare table indexes in class, here's a proposal:

class User extends Bone {
  static indexes = [
    { fields: [ 'organization_id', 'type' ] },
    { fields: [ 'email' ], unique: true },
  ]
}

which can then be consumed when calling Model.sync():

const database = new Database();
await database.sync();
// compares indexes of tables in database and Model.indexes,  
// then calls driver.addIndex or driver.removeIndex correspondingly

In the ActiveRecord like use case, we can store the indexes fetched when loading schema info from database:

const database = new Database();
await database.connect();
// if Model.indexes exists, compares the fetched and the declared, set Model.synchronized if everything match
// if Model.indexes doesn't exist, set the fetched indexes to Model.indexes
@cyjake cyjake changed the title static indexes [rfc] static indexes Sep 6, 2021
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