Live data from Hacker News

Show HN: A SQL database implemented purely in TypeScript type annotations

github.com

11–20 of 196 posts

Re: Show HN: A SQL database implemented purely in TypeScript type annotations

#11

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.

it's a bit fragile only due to my laziness, it could be done properly if this were a serious project.

Re: Show HN: A SQL database implemented purely in TypeScript type annotations

#12
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.

Re: Show HN: A SQL database implemented purely in TypeScript type annotations

#13

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.

> I’m curious why that functionality was added to the language.

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

#14
I'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

#15
post #14

I'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

Re: Show HN: A SQL database implemented purely in TypeScript type annotations

#16
post #10

I 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...

Right! That is insane - I had no idea it was possible to infer part of a string literal.

My mind is exploding at the possibilities.

Re: Show HN: A SQL database implemented purely in TypeScript type annotations

#17
post #15
post #14

I'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

Art is all about making interesting things that serve no functional purpose, though often they have useful byproducts.

This is a work of art.

Re: Show HN: A SQL database implemented purely in TypeScript type annotations

#18
post #9
post #5

The 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.

> The list of integers could be replaced by using tuples and reading their lengths to do basic arithmetic.

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

#19
post #7

Pretty 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

But if you declare a string literal as const, then the string runtime value will match the string type. So it would be possible to have a runtime result (that executes an actual db query for example) that is paired with the type result.
Post reply on HN