Live data from Hacker News

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

github.com

151–160 of 196 posts

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

#151
post #31
post #22

Could someone ELI5? Actually, I wrote a lot of code in TypeScript and I know my SQL but I have absolutely no idea what is going on here.

Since you already know TypeScript, I think it is important to note that this project uses a new TypeScript 4.1 feature called Template Literal Types to do pattern matching in order to parse the SQL string. https://devblogs.microsoft.com/typescript/announcing-typescr...

This is fascinating! On one hand, as an old guard JS developer that upscaled to TS, I often find new TS syntax incomprehensible. On the other hand I am still slowly learning new concepts. Am I correct to assume these new concepts are imported from more advanced languages? Or are these invented in TS for TS?

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

#152
post #23

TypeScript is becoming such a compelling language due to its insanely advanced type system (that allows for projects like this) that I now want to use it everywhere. I want it to become the next Python. I know Deno is supposed to be first class TypeScript but under the hood it's still a JavaScript runtime with all the baggage that comes with that. AssemblyScript is extremely interesting but last time I played with it…

I’ve only been writing TypeScript for about a year, so I might be getting something wrong, but here’s my understanding... I’m not sure your request fully makes sense. TypeScript is extremely expressive. You can specify basically any type you what... stuff like “The Number 4 Or A Function That Returns The Number 4 Or An Object With Any Attribute Which Is Equal To 4” and TS will just work with that. This SQL compiler i…

> You can specify basically any type you what... stuff like “The Number 4 Or A Function That Returns The Number 4 Or An Object With Any Attribute Which Is Equal To 4” and TS will just work with that.

Hi, an amateur here. When I started to learn JS and later TS I always disliked this expressiveness. Like when the first parameter you pass to JQuery can be anything in the world: a DOM element, or collection of elements, or an object, or a function - and only then you declare what you want to do with it. Yes, the syntax is short. And you pay for it with a lousy code readability and steep learning curve.

My question is, is there a name for this "expressiveness"? Is there a name for the opposite? I am looking at the definition of AssemblyScript: "...compiles a strict variant of TypeScript (basically JavaScript with types)". But the word "type" is again used recursively here. Is there a name for this "strict type"?

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

#153

Earlier quoted context omitted.

I was thinking about this the other day i would love for TS flag that would turn an interface into an assert const shout = (message: string) => console.log(message) into something like const assert = require('assert'); const shout = (message) => { assert(typeof message === "string"); console.log(message); } of course this doesn't work for more complicated types

You should checkout myzod, which is very close to this experience.

Or just plain zod

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

#154
post #60

Earlier quoted context omitted.

I had been thinking that WebAssembly or CLR could be the target for TypeScript and that would allow to bring her own base class libraries etc. But if you look closely again, the beaut & wide adoption of TS is because it has no "runtime" or no extra libraries or APIs to learn. Its the JS. This also makes it easy to iterate quickly on Type System and bring new features. Having its own runtime means, that wouldn't be ea…

Interesting referencing a programming language as a feminine article like that... Not saying it's wrong, just unusual to me.

People downvoting an observation on a curious use of language? If it's because of some perceived political motive, then that's really sad.

I really did just wonder why anyone would anthropomorphize a programming language, by ascribing a gendered pronoun to it.

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

#155

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…

Thinking 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…

I 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

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

#156

I love Typescript -- I just wish there were an alternate runtime (.Net core CLR/DLR or other) that offered shared-memory green and/or native threading for true support for embarrassingly parallel but not vectorized workloads. FWICT, I don't think Deno changes things here much. Typescript on the BEAM would be interesting to me as well.

I think I’d prefer compilation to Go.

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

#157
post #95

I'm interested to see if I can use these new template string type features to add more/better type checking and inference to my TS Postgres library[1]. My suspicion is that the TS recursion depth limit of 50 might limit this rather seriously. [1] https://jawj.github.io/zapatos/

Love Zapatos. Hope there’s a way to get this working!

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

#158
post #116

Earlier quoted context omitted.

> These kinds of “wacky types” are things you can statically analyze but not really “compile” per se. That’s why it’s a good fit for being transpiled down to a language with no types at all. > TL;DR, TypeScript is not really a “typed programming language”, it’s a static analysis tool. It’s not really designed to “run”. I think you have an interesting point but you've come to the wrong conclusion. Assembly language do…

This isn't strictly true, and @erikpukinskis has a point. Typed languages often do have type info that can make it to runtime. `typeof` -- virtually the only tool JS has for type reflection -- doesn't even compare to the richness of TypeScript. All of that richness is indeed lost in transpilation. In C++, for example, we have `decltype`, `typeid`, type traits, RTTI, and so on -- all of which are available at runtime.…

You don't need any type information at runtime if your type-system is strong enough. You need only types at runtime to do reflective checks, and you need those only if your type-system can't give the needed guaranties statically at compile time.

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

#159

Earlier quoted context omitted.

I’ve only been writing TypeScript for about a year, so I might be getting something wrong, but here’s my understanding... I’m not sure your request fully makes sense. TypeScript is extremely expressive. You can specify basically any type you what... stuff like “The Number 4 Or A Function That Returns The Number 4 Or An Object With Any Attribute Which Is Equal To 4” and TS will just work with that. This SQL compiler i…

> You can specify basically any type you what... stuff like “The Number 4 Or A Function That Returns The Number 4 Or An Object With Any Attribute Which Is Equal To 4” and TS will just work with that. Hi, an amateur here. When I started to learn JS and later TS I always disliked this expressiveness. Like when the first parameter you pass to JQuery can be anything in the world: a DOM element, or collection of elements,…

> Like when the first parameter you pass to JQuery can be anything in the world: a DOM element, or collection of elements, or an object, or a function

That specific part is called overloading in OOP (java). Don't know about the rest.

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

#160

Earlier quoted context omitted.

I’ve only been writing TypeScript for about a year, so I might be getting something wrong, but here’s my understanding... I’m not sure your request fully makes sense. TypeScript is extremely expressive. You can specify basically any type you what... stuff like “The Number 4 Or A Function That Returns The Number 4 Or An Object With Any Attribute Which Is Equal To 4” and TS will just work with that. This SQL compiler i…

Types do not need to have a one-to-one correspondence with runtime data structures and indeed in many type systems often do not. In the limit, a type does not need to have any runtime representation at all (this is more than just generic erasure or phantom type parameters, you can have an entire type signature that has absolutely no runtime representation of any of its parts). There is not really a fundamental differ…

A predicate is a computer program that accepts an input and returns "yes/no." A type system could be an arbitrary predicate which returns "well typed/not well typed" when given a term. But obviously there must be some difference between types and predicates, such as extensionality -- the type of an expression can be decided by examining the code alone.
Post reply on HN