Live data from Hacker News

DenoDB

github.com

121–130 of 220 posts

Re: DenoDB

#121
post #114
post #102

Earlier quoted context omitted.

It is okayish in TypeScript, but in js one subtle missing await also leads to unexpected everything. Mass-await in a language without types is a bad idea generally, but we have no alternatives for “the web”.

It's not a problem with types. It's a problem with call semantics. If `foo()` behavior depends on whether `foo` is async or not, you're implicitly introducing yield points that might lead to bugs like race conditions. Even worse: if you're calling a sync function and you (or a library author) turns it into an async function, it will silently introduce the yield point without anybody noticing. Both sync and async `foo…

You may still have race conditions with await. It doesn’t prevent anything, though I see your point if we are talking about flow control (not just net/io) via coroutines. That is race-prone in general, but most of the code is a non-leaking ‘let; await fetch(); return’ in one way or another. If someone is writing code like:

  public_state = a
  [await or autoawait] task()
  public_state = b
and then uses/modifies that state concurrently, maybe it’s time to pull their program design out of '90s.

Both sync and async `foo()` would return a `T` so TypeScript won't help with that.

  async function foo(): Promise {
    return "foo"
  }

  async function bar() {
    var s:string
    s = foo()
  }

  Type 'Promise' is not assignable to type 'string'. 
I meant this. In js you just get a promise into ‘s’ and then save ‘[object Promise]’ into a database.

Re: DenoDB

#122

During my years as a dev i have really started to dislike ORMs. They always fail in the end. SQL is universal, and transfers between languages and tech fields. This is why im pro-sql, and always try to avoid unnecessary abstractions. I have actually went back to writing pure SQL in files, and using those as params for whatever db engine i use, this makes it even possible to reuse the code in other projects (even its…

I agree that SQL is generally superior to using an ORM. However I'd argue that SQL is a lot harder to learn and significantly harder to master than any given ORM for most developers. It's very easy to write code for basic queries that performs terribly when writing SQL by hand, whereas ORMs will frequently produce code that is reasonably optimized.

In many situations the performance difference between SQL and an ORM is comparable to writing assembler code to optimize your C program: significant in theory but negligible in practice.

This gets even worse if you consider that most developers in a team will not touch the queries frequently enough to ensure their SQL skills don't get rusty eventually, even if you managed to bring them all up to speed in the first place. So in practice it'll be about deciding whether the team uses the ORM (that probably already comes with whatever framework you're using) or maintains badly written SQL with a few high performance sections nobody dares to touch because nobody remembers how it worked (e.g. pivot tables).

Re: DenoDB

#123

During my years as a dev i have really started to dislike ORMs. They always fail in the end. SQL is universal, and transfers between languages and tech fields. This is why im pro-sql, and always try to avoid unnecessary abstractions. I have actually went back to writing pure SQL in files, and using those as params for whatever db engine i use, this makes it even possible to reuse the code in other projects (even its…

I always feel weird about comments like this. Instead of discussing the merits of the actual project shared, we're going on a rant about whether or not ORMs are a good idea? It's like whenever someone shares something they made with Electron, and the comments are just Electron hate.

I am with you. And it's always the top comment.

Re: DenoDB

#124

During my years as a dev i have really started to dislike ORMs. They always fail in the end. SQL is universal, and transfers between languages and tech fields. This is why im pro-sql, and always try to avoid unnecessary abstractions. I have actually went back to writing pure SQL in files, and using those as params for whatever db engine i use, this makes it even possible to reuse the code in other projects (even its…

I always feel weird about comments like this. Instead of discussing the merits of the actual project shared, we're going on a rant about whether or not ORMs are a good idea? It's like whenever someone shares something they made with Electron, and the comments are just Electron hate.

[deleted]

Re: DenoDB

#125

ORMs are unnecessary abstraction. Check out https://github.com/ludbek/sql-compose Tools like this are the future. It's so simple yet flexible enough to handle any complex queries. It scales infinitely.

Query composing is probably 5% of the ORM framework. This is a valid thing to use. It's not an ORM replacement in any way.

I disagree. Query composing is probably 70% of an ORM framework. Rest are schema generation, serialization and validation. All of which can live outside the ORM.

Re: DenoDB

#126

Earlier quoted context omitted.

I generate Typescript types directly from a Postgres database. That works great with Knex and a bit of custom code I've written on top.

How do you know you're saving and retrieving data that correctly matches your typescript definition? Or are you just saying "trust me"?

This has been an issue for me as well. I created https://github.com/wwwouter/typed-knex to mitigate this. At first I had to do a lot of weird things, but with the evolution of TypeScript, it is getting more and more like 'normal' Knex.js. The end goal is to be nothing more than a very small wrapper, if any.

Re: DenoDB

#127

Earlier quoted context omitted.

Query composing is probably 5% of the ORM framework. This is a valid thing to use. It's not an ORM replacement in any way.

I disagree. Query composing is probably 70% of an ORM framework. Rest are schema generation, serialization and validation. All of which can live outside the ORM.

Mapping to actual objects. Type mapping. Merging requests over relationships. Transaction integration. Dealing with dirty markers and writebacks. All of those along with validation depend on the database and object formats. Those are why ORMs exist in the first place.

If you take them out, what you have left is a repository pattern with some struct mapping helpers only. Which is fine if you want that, but you'd miss the "R" and the "O".

Re: DenoDB

#128

During my years as a dev i have really started to dislike ORMs. They always fail in the end. SQL is universal, and transfers between languages and tech fields. This is why im pro-sql, and always try to avoid unnecessary abstractions. I have actually went back to writing pure SQL in files, and using those as params for whatever db engine i use, this makes it even possible to reuse the code in other projects (even its…

Every single time I've seen somebody not using ORM on something more complicated than a todo list side project, the alternative becomes an imposible to understand and maintain mess of joins, custom made query builders, manual computation of computed fields, custom calls to fetch related data and hand made crappy shell scripts to do schema migrations.

Also, most of the times this happens to come always from ecosystems which don't have a good ORM... such as Go, Node (up until recently... Prisma is pretty good), etc.

Re: DenoDB

#129
post #128

During my years as a dev i have really started to dislike ORMs. They always fail in the end. SQL is universal, and transfers between languages and tech fields. This is why im pro-sql, and always try to avoid unnecessary abstractions. I have actually went back to writing pure SQL in files, and using those as params for whatever db engine i use, this makes it even possible to reuse the code in other projects (even its…

Every single time I've seen somebody not using ORM on something more complicated than a todo list side project, the alternative becomes an imposible to understand and maintain mess of joins, custom made query builders, manual computation of computed fields, custom calls to fetch related data and hand made crappy shell scripts to do schema migrations. Also, most of the times this happens to come always from ecosystems…

At least in node, there are migration tools that let you write vanilla SQL. My current project is ORMless, and I think it’s turning out just fine. Time will tell.

Re: DenoDB

#130

Earlier quoted context omitted.

If you omit await, the returned calue is a promise which you can keep for later, instead of waiting right now. Say you want to kick off something you know will take a while, do some ofher things (async or not), THEN wait for the original async operation. (Or even say, wait for multiple promises to finish)

Thanks, I understand it, but my issue is that more and more libraries and functions are now asynchronous, so the await prefix is going to be everywhere. Maybe it should've been the other way around - when calling an asynchronous function you get the result by default, and can get the promise if you want (as it happens much less frequently): const res1 = func1(); // async or not, wait for the result const res2 = func2…

> Maybe it should've been the other way around - when calling an asynchronous function you get the result by default, and can get the promise if you want

I don't know why you're getting downvoted, indeed maybe it should have been the other way around. I personally would have preferred it, but there's 2 main problems:

The first is backward compatibility. If the function returns a promise in older JS implementations, it needs to continue to do so. If the promises are now magically unwrapped unless there's a `nowait`, many things would break.

The second is the single-threaded nature of JS, both Node webservers and browsers. JS execution is (usually) single-threaded, and _needs_ a lot of async calls to give the illusion that it's doing things in parallel (eg serve several HTTP requests). This illusion works well-ish because we are _forced_ to have so much asynchronicity, if it was optional it would be a huge pain for the dev to manually ensure that they are sprinking asynchronicity enough: the concurrency abstraction would leak much more than it already does.

Post reply on HN