Live data from Hacker News

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

github.com

141–150 of 196 posts

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

#141

Earlier quoted context omitted.

Are you really calling this ergonomic? https://github.com/codemix/ts-sql/blob/master/src/Evaluator.... Same thing but actually readable and maintanable would've been better implemented as a compile-time (build-time) script, basically source code generation.

Nobody said it's ergonomic to implement SQL in a type system. It was simply an answer to your question "What do you think is advanced about TS' type system and why?". It's advanced because you're able to implement SQL in types alone when with most languages you couldn't. The question on ergonomics is for the other languages where you can do this is it more or less ergonomic than this. Again that doesn't mean this IS…

This thread made me read about conditional types in TS and in general more about its type system. I was ignorant. I agree now that it's advanced. Previously I only heard bad things about it without bothering to study it myself. Turns out, it's not all bad, there is some good as well. Still wouldn't want to work with it, ever; but that's beside the point.

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

#142
Very interesting project. If you want a deep dive into TypeScript generics, this project's code is truly a must-read! This project really shows how powerful TypeScript has become over the years.

Shameless plug: we're also working on project in the same domain. It actually uses the TypeScript compiler API to generate/update your SQL schema's and a typesafe (mongo like) API on top PostgreSQL. It's still very early stage, but if you're interested: https://samen.io

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

#143

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…

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

Yes, 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.

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

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

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

#145

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 would absolutely love to work with the TypeScript type system on BEAM, if it didn't leak as much of Erlang particulars as other BEAM languages like Elixir do.

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

#146

Earlier quoted context omitted.

> Haskell has a much more expressive type system than Elm, but still lags behind Typescript unless you turn on a truly gargantuan number of extensions. IIUC: it's not a total order, Haskell (even '98) has things TypeScript doesn't[0], and TypeScript has things that Haskell (even with extensions) doesn't[1]. [0]: eg. higher-kinded types [1]: eg. (convenient) row polymorphism

Yeah you're right it's not a total order. I was being fast and loose and conveying a subjective feeling. RE row polymorphism, Typescript doesn't quite have what users of ML-like languages are asking for when they want row polymorphism (which is usually parametric polymorphism rather than subtyping). But it's close. As for convenient... well I'd argue by the time you've got the whole cornucopia of GHC extensions at th…

> RE row polymorphism, Typescript doesn't quite have what users of ML-like languages are asking for when they want row polymorphism (which is usually parametric polymorphism rather than subtyping). But it's close.

How would you distinguish this from the following?

    function foo(x: T & {field: number}): T {
        ...
    }
> As for convenient... well I'd argue by the time you've got the whole cornucopia of GHC extensions at the top of your file nothing is quite convenient at that point.

That was one part of my point. That said, I think the problems implied by language extensions are often exaggerated (probably not deliberately so, most of the time).

The other part of my point was that even with all the extensions you need, I've not found good row types in Haskell, although the particular failings vary by approach. Which isn't to say I can't get something that works well enough for my particular situation most of the time.

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

#147
post #118

Earlier quoted context omitted.

From years of real-world experience, it's rare to run into types that are too complex to easily understand. The syntax is pretty easy to read, and the compiler and language service make it easy to navigate types, even if you haven't looked at the source for them yet.

FWIW I find that TypeScript types can sometimes be overwhelming or hard to decipher, especially some third-party library type definitions. The connect function from react-redux is one example: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/d07d... Since types can get really complex, I feel a need to be conscious of avoiding complexity when writing types myself, unless the value is enough to justify a hard-to…

This is the complexity introduced when applying static types to a vanilla JS codebase, imo. It's easy to get crazy with types in vanilla JS. Adding Typescript forces you to resolve the different types explicitly and it can get hairy.

What this really demonstrates to me is the difference between starting with TS vs migrating to it. Code that has to think about the types the first time it is being built is going to be better structured, on average, than purely dynamic code.

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

#148
post #56
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…

If you're impressed with TypeScript, you should definitely check out ReScript (formerly BuckleScript). Its type system is clean and sound, and yet compiles to native JS without overhead. https://rescript-lang.org/docs/manual/latest/introduction

Wow, when I read this earlier, I was dismissive (because I am really happy with typescript). But reading through the comparison - it seems to have many of the great parts I like in Typescript.

Then, I noticed it has the pipe operator! I'm going to be giving this a try.

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

#149

Earlier quoted context omitted.

Yeah you're right it's not a total order. I was being fast and loose and conveying a subjective feeling. RE row polymorphism, Typescript doesn't quite have what users of ML-like languages are asking for when they want row polymorphism (which is usually parametric polymorphism rather than subtyping). But it's close. As for convenient... well I'd argue by the time you've got the whole cornucopia of GHC extensions at th…

> RE row polymorphism, Typescript doesn't quite have what users of ML-like languages are asking for when they want row polymorphism (which is usually parametric polymorphism rather than subtyping). But it's close. How would you distinguish this from the following? function foo (x: T & {field: number}): T { ... } > As for convenient... well I'd argue by the time you've got the whole cornucopia of GHC extensions at the…

    function foo(x: T & {field: number}): T {
        return x;
    }
    
    function bar(x: T & {field: number}): T {
        const x0 = foo(x);
        // type error because x0 doesn't have field
        // would compile fine with row types
        const x1 = foo(x0);
        return x1;
    }
Yes it's true. I also sorely miss the lack of row types in Haskell (I miss them even in something like Idris where you can create them more easily, but it's still not great compared to first-class support).

EDIT: I may be being dumb. You could probably fix this by adding an intersection type again on the right-hand side. I think there was something else I was missing from TS, but I'll have to noodle on it a bit more.

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

#150

Earlier quoted context omitted.

> RE row polymorphism, Typescript doesn't quite have what users of ML-like languages are asking for when they want row polymorphism (which is usually parametric polymorphism rather than subtyping). But it's close. How would you distinguish this from the following? function foo (x: T & {field: number}): T { ... } > As for convenient... well I'd argue by the time you've got the whole cornucopia of GHC extensions at the…

function foo (x: T & {field: number}): T { return x; } function bar (x: T & {field: number}): T { const x0 = foo(x); // type error because x0 doesn't have field // would compile fine with row types const x1 = foo(x0); return x1; } Yes it's true. I also sorely miss the lack of row types in Haskell (I miss them even in something like Idris where you can create them more easily, but it's still not great compared to firs…

Not dumb, you answered the question I asked :D

But yeah, I agree that duplicating the intersection produces another interesting question.

In any case, "convenient approximation of row types" probably still applies to TS more than Haskell. And possibly also "more convenient row types", but that remains TBD.

Post reply on HN