Live data from Hacker News

Flyweight: An ORM for SQLite

github.com

31–40 of 105 posts

Re: Flyweight: An ORM for SQLite

#31
post #22
post #9

Most engineers who say they want an ORM, really want query composition.

What’s a good solution for that without a classic ORM?

Conditional text interpolation with named parameter bindings works quite well. We’ve basically abandoned the ORM for select queries at work as we find this approach more readable.

Re: Flyweight: An ORM for SQLite

#32

Does anyone know of a library similar to slonik[0] for SQLite in the NodeJS space? I generally reach for TypeORM and have tried MikroORM lately but didn’t really like it. But what I really want is something like slonik which is more focused on querying than relational mapping. [0]: https://github.com/gajus/slonik

[deleted]

Re: Flyweight: An ORM for SQLite

#33

Does anyone know of a library similar to slonik[0] for SQLite in the NodeJS space? I generally reach for TypeORM and have tried MikroORM lately but didn’t really like it. But what I really want is something like slonik which is more focused on querying than relational mapping. [0]: https://github.com/gajus/slonik

MikroOrm is a pretty fantastic project IMO.

It uses Knex as the query builder so maybe you can just use that directly: https://knexjs.org/

Although, I would use Mikro still to manage schema and migrations. Then drop down to Knex: https://mikro-orm.io/docs/query-builder#using-knexjs

Re: Flyweight: An ORM for SQLite

#34
post #9

Most engineers who say they want an ORM, really want query composition.

I think the data mapping part is pretty important: a programmatic way to map from SQL result sets to objects. That stuff is incredibly tedious (and error prone) when you do it manually.

Re: Flyweight: An ORM for SQLite

#36

const fights = await db.fights.get({ cardId: 9, titleFight: true }); translates to select * from fights where cardId = 9 and titleFight = 1; Confession: something about ORMs has never clicked with me.. none of them ever seem simpler than SQL.

You're coming at it from a slightly wrong angle. You are completely right that for queries, there's really no gain, you just end up having to learn both SQL and whatever your ORMs DSL is.

Where ORMs are useful is once you have your objects. The usefulness of an ORM is being able to say:

  user.email = 'new@example.com'
  user.groups.append('admin')
  user.save()
Also being able to work on your data in objects or structure native to your programming language means that you can leverage both the strengths of the language and the database server. Some operations are much simpler to do in Python or C#, compared to SQL. In other scenarios you really need to let the database do its thing. Again, you do have a point, because believing that you can skip learning SQL and just rely on the ORM will get you into trouble.

One other feature of ORMs is that they allow you to write code that will run on multiple databases, but at the cost of not being able to use the more advanced database features. For many CRUD applications that is a price worth paying though.

Re: Flyweight: An ORM for SQLite

#37
Here's a python (pip) version of the same concept:

https://github.com/Aperocky/sqlitedao

https://pypi.org/project/sqlitedao

Same concept, huge speed boost to personal projects. ORM is great because you can abstract items in memory directly into persistence, and define the relation in programming language instead of SQL.

Re: Flyweight: An ORM for SQLite

#38
post #9

Most engineers who say they want an ORM, really want query composition.

Not really, they (I) wanted `insert(Item)` that just inserted the item into the table.

I don't really care about the query, just that it's inserted correctly, along with other operations that an ORM provide (get/delete/update,etc)

Re: Flyweight: An ORM for SQLite

#39

const fights = await db.fights.get({ cardId: 9, titleFight: true }); translates to select * from fights where cardId = 9 and titleFight = 1; Confession: something about ORMs has never clicked with me.. none of them ever seem simpler than SQL.

It's more about the Mapping than the querying. Luckily good ORMs let you fetch your objects using... SQL, which is a fine language for querying (doh): for p in Person.objects.raw('SELECT * FROM myapp_person'): print(p)

This sort of thing can be very good in the right hands, but it also facilitates the antipattern of select * with no conditions, then doing the real selection of columns and filtering of rows in code.

Re: Flyweight: An ORM for SQLite

#40

Why a whole new ORM and not an SQLite adapter for an existing ORM?

it's npm.

Jokes aside, as someone who wrote a python sqlite ORM (shameless plug: `pip install sqlitedao`), my reason was to have a minimal ORM for personal project, the entire active source is contained in one file and it works for majority of the use cases (i.e. insert_item, get_item, etc).

Post reply on HN