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

SQLite Schema Discovery #25

Closed
billy1624 opened this issue Nov 24, 2021 · 5 comments
Closed

SQLite Schema Discovery #25

billy1624 opened this issue Nov 24, 2021 · 5 comments
Assignees

Comments

@billy1624
Copy link
Member

billy1624 commented Nov 24, 2021

I found a SQLite version of Sakila schema for testing

Discovery

  1. Getting column info: https://www.sqlite.org/pragma.html#pragma_table_info
    image

  2. Getting foreign key info: https://www.sqlite.org/pragma.html#pragma_foreign_key_list
    image

  3. Getting index & primary key info: https://www.sqlite.org/pragma.html#pragma_index_list
    image

Parser

Parse the above result into schema definition structs. Including information like

  • table name
  • columns
    • name
    • data type
      • length (if any)
    • default value
    • nullable
    • primary key
    • auto increment
  • foreign key constraints

Writer

Converting the discovered & parsed table info into sea_query::TableCreateStatement.

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 24, 2021

No, we should not write a custom SQL parser

I guess this may help?

https://stackoverflow.com/questions/604939/how-can-i-get-the-list-of-a-columns-in-a-table-for-a-sqlite-database

@billy1624
Copy link
Member Author

billy1624 commented Nov 24, 2021

No, we should not write a custom SQL parser

I guess this may help?

https://stackoverflow.com/questions/604939/how-can-i-get-the-list-of-a-columns-in-a-table-for-a-sqlite-database

Yes, we could use a combination of SQLite pragma statements for

  1. Getting column info: https://www.sqlite.org/pragma.html#pragma_table_info

  2. Getting foreign key info: https://www.sqlite.org/pragma.html#pragma_foreign_key_list

  3. Getting index & primary key info: https://www.sqlite.org/pragma.html#pragma_index_list

@billy1624
Copy link
Member Author

Hey @charleschege, just a quick check, are you taking this issue?

@charleschege
Copy link
Contributor

Hi @billy1624 I am working on it

@billy1624
Copy link
Member Author

Thanks!! Do ping me if you need any help, either here or Discord, both fine.

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

3 participants