I’m impressed/fascinated/horrified by the way it parses a string into a type with a variant of template literal syntax—though it looks like the parsing is probably very fragile. I’m curious why that functionality was added to the language. The end result is actually pretty approachable.
Show HN: A SQL database implemented purely in TypeScript type annotations
11–20 of 196 posts
Re: Show HN: A SQL database implemented purely in TypeScript type annotations
#12It’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.
Re: Show HN: A SQL database implemented purely in TypeScript type annotations
#13I’m impressed/fascinated/horrified by the way it parses a string into a type with a variant of template literal syntax—though it looks like the parsing is probably very fragile. I’m curious why that functionality was added to the language. The end result is actually pretty approachable.
I think it's because there are a whole bunch of APIs in javascript where there is a function like `.get("foo")` that internally calls a function called `getFoo` or similar. And this functionality allows such functions to be accurately typed. It basically allows strong typing for stringly typed functions (which are pretty common in dynamic languages)
Re: Show HN: A SQL database implemented purely in TypeScript type annotations
#14Re: Show HN: A SQL database implemented purely in TypeScript type annotations
#15I'm viewing this on my phone, so maybe I'm missing something, but isn't this getting all of its typing information from you explicitly declaring a result set `as const`, and then subsequently doing `typeof` that const value? How does that help in real world queries, where the result sets are dynamic? Also, how does it help beyond just naturally declaring a result set as const without the use of this library?
Re: Show HN: A SQL database implemented purely in TypeScript type annotations
#16I had no idea you could compose string literal types AND infer variables using interpolation syntax in the context of conditional types. I am salivating at the potential use cases for this...
My mind is exploding at the possibilities.
Re: Show HN: A SQL database implemented purely in TypeScript type annotations
#17I'm viewing this on my phone, so maybe I'm missing something, but isn't this getting all of its typing information from you explicitly declaring a result set `as const`, and then subsequently doing `typeof` that const value? How does that help in real world queries, where the result sets are dynamic? Also, how does it help beyond just naturally declaring a result set as const without the use of this library?
oh let's be clear there's no sensible real world use cases of this thing. it's a demonstration of what TS's type system can do
This is a work of art.
Re: Show HN: A SQL database implemented purely in TypeScript type annotations
#18The implementation isn't even that horrible. Ignoring the integer list. That workaround is still hillarious to me. Anyway, it seems both impressive that someone did this and that it actually works. Weird how typescript has the nicest typelevel programming I know, even nicer than some dependent ones. It probably is the only language one where autocompletion properly works with computed types?
> The implementation isn't even that horrible You're making me blush! The list of integers could be replaced by using tuples and reading their lengths to do basic arithmetic. Might run into recursion limits though.
Is that anything like church encoding?
https://www.wikiwand.com/en/Church_encoding#/Church_numerals
Re: Show HN: A SQL database implemented purely in TypeScript type annotations
#19Pretty interesting, but it doesn't seem to be possible to use the resulting values? Except as type declarations of course. Also, the playground link either fails (there are several errors) or doesn't produce any output.
yeah Typescript is compile-time-only type system, you can only use it as a type. still cool though
Re: Show HN: A SQL database implemented purely in TypeScript type annotations
#20JSON parser https://twitter.com/buildsghost/status/1301976526603206657
This one is more realistic: Typed route params https://twitter.com/danvdk/status/1301707026507198464