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 support #467

Open
stephenh opened this issue Nov 13, 2022 · 4 comments · May be fixed by #468
Open

SQLite support #467

stephenh opened this issue Nov 13, 2022 · 4 comments · May be fixed by #468

Comments

@stephenh
Copy link
Collaborator

Just tracking what would be necessary, after a very small spike:

  • Big: No pg-structure for SQLite; sqlite doesn't even support information_schema, it has a sqlite_master that just as the raw DDL for each object, which would then need to be parsed :-|
    • Instead of trying to reflect out the schema, try the Prisma approach (and even it's literal file format) of declaring the model outside the db
  • Medium: No SEQUENCEs, so would need to do INSERT+UPDATEs
  • Good: Does support deferred FK constraints
stephenh added a commit that referenced this issue Nov 13, 2022
Fixes #467
@stephenh stephenh linked a pull request Nov 13, 2022 that will close this issue
@AustinGil
Copy link

Would love to see this :)

@stephenh
Copy link
Collaborator Author

stephenh commented Jul 8, 2023

Ah nice, hey @AustinGil !

Kinda surprised, I did some googling after seeing your comment--one of the blockers here was lack of sequences in sqlite, but turns out sqlite's autoincrement primary keys have an internal sqlite_sequence table that can very likely be used (carefully, pending more research) to mimic Joist's up-front/pre-INSERT assignment of entity ids, which was one of the pg-isms that would be ~not-hard-but-annoying to move away from:

sqlite> create table bar (id integer primary key autoincrement);
sqlite> insert into bar (id) values (null);
sqlite> select * from bar;
1
sqlite> select * from sqlite_sequence;
bar|1
-- pretend joist bulk pre-assigns 10 new ids for bar entities 
sqlite> update sqlite_sequence set seq = 10;
sqlite> insert into bar (id) values (null);
sqlite> select * from bar;
1
11

So pulling the metadata from the SQLite schema is probably the biggest blocker at this point.

@AustinGil
Copy link

Yeah, I wish I knew more about db adapters so I could be of service, but I'm more of a frontend guy. Trying to find an ORM I really like, and hopefully one that works with SQLite. I listened to the JS Party on this one and it sounds great.

@stephenh
Copy link
Collaborator Author

Np! Especially for the first one or two "not postgres" adapters, it will likely be something myself/one of our core maintainers will need to do, just to even get Joist's adapter layer setup well to really do "more than just postgres".

I did some more googling and really seems like the blocker is finding a "pg-structure but for sqlite"--like this sqlite_master table will tell you all of the tables in the database, but to get the columns / foreign keys / etc., you have to parse the CREATE TABLE DDL. Which just doesn't sound like fun... And I haven't found anything on npm that will do it for us.

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

Successfully merging a pull request may close this issue.

2 participants