3 ms·
Nice! I built something similar - A set of scripts that generate SQL statements from typescript types to wrap a PostgresSql db. It’s more a hybrid data structu
by ricksharp 6y ago
Nice! I built something similar - A set of scripts that generate SQL statements from typescript types to wrap a PostgresSql db.
It’s more a hybrid data structure where only relationships and certain fields become columns (which can be indexed and searched) and most of the other data becomes a Json column.
I wasn’t completely satisfied with the final results, but it does at least allow me to add additional data fields without having to migrate the db structure and to use Postgres sql to filter and page data.
I think the goal of being able to define a true database in typescript is great and I look forward to trying your code.
It’s also pretty cool if you are able to extract types from a string using the type system - that’s next level typescript wizardry.
- ricksharp 6y agoThinking about this more. I think this project has some promising practical uses when combined with code generation from the typescript ast (which is what my project does). Since the type system can parse the SQL strings, then it becomes possible to include those strings as a source for the ast. Then the code generator can use the typescript parser to parse all the types and the sql. From that it can generate all the required code to create the runtime queries. I don’t like ORMs because they make it very difficult to write complex queries (and my own attempt did not solve that very well - I still had to manually type any complex queries). However, if this could essentially allow writing a complex query in raw sql and have it type-checked at code-time, it becomes easier to use. Then the code generator would convert that into a type-safe runtime library which solves 2 problems: 1. The poor editor performance of the type system inferring so many nested types. 2. Actually having a runtime that executes the queries. The outstanding problem would be migrations... Anyway, this is certainly a thought provoking project.
- thrashh 6y agoI find the ORM in SQLAlchemy pretty cool — I’ve really written complex queries as if I had witten it by hand but then finally mapped them into the ORM at the end with like a line of code. However it was a learning curve to figure out how to do it at first, but I didn’t have to drop down to raw SQL
- gfody 6y agomy thoughts as well. compile-time checked arbitrary sql would defeat the purpose of so many abominable ORMs. make it work with DDL instead of sample data and you've really got something nice!
- throwaway7422u 6y agoThis project does exactly that (TypeScript/PostgreSQL): https://github.com/MedFlyt/mfsqlchecker https://github.com/MedFlyt/mfsqlchecker
- ricksharp 6y agoThat looks pretty nice. I’ll have to check that out.
- johnghanks 6y ago> I built something similar - A set of scripts that generate SQL statements from typescript types to wrap a PostgresSql db. If you think these are similar I don't think you understand what this is / what it's actually doing.
- ricksharp 6y agoYes, I only meant similar in the sense that it attempts to use typescript types as the primary source for the definition of the database schema. I agree my wording could have been better.