-
Notifications
You must be signed in to change notification settings - Fork 24
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
Support SQLite converter into Recap #418
Comments
Oh, gosh, I can't believe I didn't think of adding this! 🤣 Seems so obvious now that you opened the issue. 😝 |
Using the DDL to represent the schema is an interesting (lazy?) choice for SQLite. But thinking about it a bit more... if we implement that for SQLite, we might be able to reuse that code for pulling schema from other databases assuming the DDL dumps are compatible. Potentially replace postgresql and mysql client/converter code using that. |
Perhaps sqlglot can be of use? |
I think this is the key part of your statement. I suspect information_schema will be more robust. Perhaps start with SQLite impl only, and see where that leads... |
Poked around a bit. Looks like there are a few options: https://www.sqlitetutorial.net/sqlite-describe-table/ The |
@mjperrone do y'all want to take this or should I? I don't mind doing it, but I don't want to start if y'all want to take it for learning experience or whatever. =-) |
We aren't in a rush to implement this one, so I dont think we will get to it before you do if you're interested in it |
Nice! I've been hankering to write a bit of code, so I'll take a crack at this. |
Starting to poke at this now. |
@mjperrone been doing some digging on SQLite data types.
Here's what I recommend:
This is a very straight-forward to implement. Is this OK with you? Alternatively, we could add support for both STRICT and non-STRICT tables. This gets a lot messier. Dates, for example, are a mess in SQLite; it accepts both strings or ints in the column. 😢 WDYT? What is your use case here? Do you have any practical examples of SQLite schemas you're dealing with? /cc @adrianisk |
Some more details on affinity matching: https://medium.com/@SullivanArielle/type-affinity-5936cee17c35 Note that there are two things happening here:
We're only interested in column types (1). As such, after further reading, I think the converter can handle both affinity and STRICT types. I'll include a flag similar to the PG converter's I also plan on implementing scale/precision support and char octet length. They'll only be used when |
@criccomini I'll try to get some more details for you. |
Recap can now read SQLite schemas as Recap types. SQLite's schema system is somewhat strange. Some notes: 1. Any column can store any type. 2. SQLite has 5 storage classes (null, int, real, text, blob). 3. STRICT forces column types to be the storage types. 4. non-STRICT tables allow any strings for column types. 5. non-STRICT column types are hints to coerce types as they're written to disk. 6. Parenthesis in types (e.g. DOUBLE(6, 2)) are ignored by SQLite. See https://www.sqlite.org/datatype3.html#storage_classes_and_datatypes for more details. With all of this in mind, Recap's SQLiteConverter works according to SQLite's affinity rules. This means: 1. Unknown types are treated as "ANY", which is a union of all storage types. 2. SQLiteConverter pays attention to precision/scale for REAL, etc. 3. SQLiteConverter pays attention to lengths for VARCHAR(255), etc. 4. SQLiteConverter treats date, datetime, time, and timestamp as ANY types. Closes #418
@mjperrone I have a PR up here: It's still WIP for tests, but I want feedback. I'm going to add CLI tests for |
Recap can now read SQLite schemas as Recap types. SQLite's schema system is somewhat strange. Some notes: 1. Any column can store any type. 2. SQLite has 5 storage classes (null, int, real, text, blob). 3. STRICT forces column types to be the storage types. 4. non-STRICT tables allow any strings for column types. 5. non-STRICT column types are hints to coerce types as they're written to disk. 6. Parenthesis in types (e.g. DOUBLE(6, 2)) are ignored by SQLite. See https://www.sqlite.org/datatype3.html#storage_classes_and_datatypes for more details. With all of this in mind, Recap's SQLiteConverter works according to SQLite's affinity rules. This means: 1. Unknown types are treated as "ANY", which is a union of all storage types. 2. SQLiteConverter pays attention to precision/scale for REAL, etc. 3. SQLiteConverter pays attention to lengths for VARCHAR(255), etc. 4. SQLiteConverter treats date, datetime, time, and timestamp as ANY types. Closes #418
Recap can now read SQLite schemas as Recap types. SQLite's schema system is somewhat strange. Some notes: 1. Any column can store any type. 2. SQLite has 5 storage classes (null, int, real, text, blob). 3. STRICT forces column types to be the storage types. 4. non-STRICT tables allow any strings for column types. 5. non-STRICT column types are hints to coerce types as they're written to disk. 6. Parenthesis in types (e.g. DOUBLE(6, 2)) are ignored by SQLite. See https://www.sqlite.org/datatype3.html#storage_classes_and_datatypes for more details. With all of this in mind, Recap's SQLiteConverter works according to SQLite's affinity rules. This means: 1. Unknown types are treated as "ANY", which is a union of all storage types. 2. SQLiteConverter pays attention to precision/scale for REAL, etc. 3. SQLiteConverter pays attention to lengths for VARCHAR(255), etc. 4. SQLiteConverter treats date, datetime, time, and timestamp as ANY types. Closes #418
Recap can now read SQLite schemas as Recap types. SQLite's schema system is somewhat strange. Some notes: 1. Any column can store any type. 2. SQLite has 5 storage classes (null, int, real, text, blob). 3. STRICT forces column types to be the storage types. 4. non-STRICT tables allow any strings for column types. 5. non-STRICT column types are hints to coerce types as they're written to disk. 6. Parenthesis in types (e.g. DOUBLE(6, 2)) are ignored by SQLite. See https://www.sqlite.org/datatype3.html#storage_classes_and_datatypes for more details. With all of this in mind, Recap's SQLiteConverter works according to SQLite's affinity rules. This means: 1. Unknown types are treated as "ANY", which is a union of all storage types. 2. SQLiteConverter pays attention to precision/scale for REAL, etc. 3. SQLiteConverter pays attention to lengths for VARCHAR(255), etc. 4. SQLiteConverter treats date, datetime, time, and timestamp as ANY types. Closes #418
Recap can now read SQLite schemas as Recap types. SQLite's schema system is somewhat strange. Some notes: 1. Any column can store any type. 2. SQLite has 5 storage classes (null, int, real, text, blob). 3. STRICT forces column types to be the storage types. 4. non-STRICT tables allow any strings for column types. 5. non-STRICT column types are hints to coerce types as they're written to disk. 6. Parenthesis in types (e.g. DOUBLE(6, 2)) are ignored by SQLite. See https://www.sqlite.org/datatype3.html#storage_classes_and_datatypes for more details. With all of this in mind, Recap's SQLiteConverter works according to SQLite's affinity rules. This means: 1. Unknown types are treated as "ANY", which is a union of all storage types. 2. SQLiteConverter pays attention to precision/scale for REAL, etc. 3. SQLiteConverter pays attention to lengths for VARCHAR(255), etc. 4. SQLiteConverter treats date, datetime, time, and timestamp as ANY types. Closes #418
I may be able to give this a look on Monday |
Recap can now read SQLite schemas as Recap types. SQLite's schema system is somewhat strange. Some notes: 1. Any column can store any type. 2. SQLite has 5 storage classes (null, int, real, text, blob). 3. STRICT forces column types to be the storage types. 4. non-STRICT tables allow any strings for column types. 5. non-STRICT column types are hints to coerce types as they're written to disk. 6. Parenthesis in types (e.g. DOUBLE(6, 2)) are ignored by SQLite. See https://www.sqlite.org/datatype3.html#storage_classes_and_datatypes for more details. With all of this in mind, Recap's SQLiteConverter works according to SQLite's affinity rules. This means: 1. Unknown types are treated as "ANY", which is a union of all storage types. 2. SQLiteConverter pays attention to precision/scale for REAL, etc. 3. SQLiteConverter pays attention to lengths for VARCHAR(255), etc. 4. SQLiteConverter treats date, datetime, time, and timestamp as ANY types. Closes #418
SQLite schematab docs:
The
sql
field is the SQL DDL that would create the table.To implement this, one would create a recap SQLite client to grab that DDL and then create a recap SQLite converter to turn it into recap types.
The text was updated successfully, but these errors were encountered: