top | item 42485499

Show HN: NoSQL, but it's SQLite

98 points| vsroy | 1 year ago |gist.github.com

Manipulate your SQLite database like a giant Javascript object. Built with o1.

39 comments

order

eterm|1 year ago

It's stored :memory:, there exists the same interface with:

    let x = {}
    x['foo'] = bar
This is a parody because the implementation is hidden, and I'm not convinced the implementation isn't just newing an object.

vsroy|1 year ago

The implementation is very clearly included, if you... scrolled down.

And the point is, you could easy do `const db = new Database("./database.sqlite")` instead.

The wrapper makes it so manipulating your database is just like manipulating a plain Javascript object.

jazzyjackson|1 year ago

Not a database, just a map of json strings where you can update the json stored at some key. You could write the same interface on top of localStorage.

vsroy|1 year ago

Yes that is exactly what it is! It's basically a very small upgrade over my favorite database: A JSON-file :)

b33f|1 year ago

Couchbase mobile has been doing this for over a decade and early versions of membase 15 years ago were using a sqlite backend as a noSQL JSON datastore

messe|1 year ago

I'm using something like this for a small personal project that's only going to have a couple of users. Basically, just an app for myself and my girlfriend for all of the various restaurants, movies, recipes, tv shows, locations, etc. that we plan to go to/do at some point in the future. It's basically just a glorified todo list that uses APIs (TheMovieDataBase, OpenStreetMap, etc.) to grab additional metadata and images to present everything nicely

I want us both to be able to make notes/add ratings to each item, so the set of tables looks like this:

    - TodoItems
    - Notes
    - Ratings
Where every TodoItem can have multiple Ratings/Notes attached. Because each of the TodoItems is going to be of a different type with different metadata depending on the type of item (IMDB/TMDB id, image url, GPS location), and I want it to be extensible in future, its schema has ended up looking like this:

    CREATE TABLE TodoItems (
      id INTEGER PRIMARY KEY NOT NULL,
      kind TEXT NOT NULL,
      metadata BLOB NOT NULL
    );
With SQLite's json manipulation functions, it's actually pretty pleasant to work with. As it grows I might end up adding some indexes, but for now the performance seems like it will be fine for this very low traffic use case. And it makes deployment and backups incredibly simple.

motorest|1 year ago

Postgres added native support for JSON in 2012. People have been using RDBMS to store denormalized data and even as a key-value store for way longer than that. In fact, it's very hard not to do that

senko|1 year ago

I've built this (unironically) for Python: https://github.com/senko/dante

It combines the convenience of SQLite (nothing to install) with the convenience of just throwing stuff in a dict. Perfect for quick prototypes/mockups.

adammarples|1 year ago

So it's a lot like the shelve builtin module?

iLoveOncall|1 year ago

The worst of both worlds, perfection.

redwood|1 year ago

PowerSync does something similar I believe

stanac|1 year ago

I did something similar with dotnet and linq. Idea was to create something like marten but for sqlite instead of postgres. Stopped working on it some time ago, the thing that was really slow was de/serialization, but with new source generators for json maybe it can be sped up.

revskill|1 year ago

At work, we're using sql server, and i stored all json as base64 string though.

p2detar|1 year ago

Not sure what your exact use case is, I'm curious actually, but storing JSON strings should work much better. JSON functions are supported since SQL Server 2016 [0]. This is how I do it atm. I store only indexible content in table columns and everything else goes into an `attributes` JSON column. MSSQL supports indexes even on JSON fields, but I have not tried that, yet.

0 - https://learn.microsoft.com/en-us/sql/relational-databases/j...

szundi|1 year ago

This needs some explanation

dontdoxxme|1 year ago

Submitted it to The Daily WTF yet?

richrichie|1 year ago

Doesn’t sqlite-utils does this and more, better?

keepamovin|1 year ago

Beautiful. Please turn it into a repository. You wrangled that AI masterfully for this. Well done! :)

_ugfj|1 year ago

> Built with o1.

Yes, yes, database with AI written code. NoSQL with a database that can't be trusted with your data? I. have. seen. this. before. To quote a classic:

> I suggest you pipe your data to devnull it will be very fast

In defense of the database that video was about, I worked as a software architect for the company which became the first commercial user of it, Eliot hilariously didn't want to accept money for support at first. Good old days. However, around 2015 when all three large open source SQL databases --- SQLite, PostgreSQL, MySQL -- added JSON support I felt there was no more need for these NoSQL systems, though.

chx|1 year ago

[deleted]

vsroy|1 year ago

dang -- why was this flagged? Seems like a perfectly reasonable post.

dang|1 year ago

Users flagged it. We can only guess why users flag things, but there are usually clues in the comments. I've turned the flags off now.

p.s. @dang doesn't work - you have to email hn@ycombinator.com if you want mostly-guaranteed message delivery.

hda111|1 year ago

Maybe because it’s written with a LLM

cwillu|1 year ago

[deleted]

cwillu|1 year ago

I'd be a little less reflexively hostile if the prompting used to generate it was prominently included, so that it was at least possible to see which properties of the output were deliberately asked for.

When I read a piece of code I don't understand, ideally I'm able to assume that the author intended what was written, and learn something when I figure out why. With AI generated code, I can't do that: the original author is more or less destroyed once the context is gone; at best I can ask someone who was kinda-sorta around when the author wrote it (i.e. the person who prompted it). At worst I'm really just asking someone (or something) else to guess what was intended.

Even granting that the generated code is implementing a coherent design (and that's a big if!), what we're left with is a very quick way to generate legacy code who's author is no longer around to answer questions. Such legacy code, if it's been proven to work, I might just stick a “don't touch this” sign on it, but if it starts causing any problems, I'd end up doing a ground-up rewrite if only to (potentially) understand what problems and concerns influenced the design to make it what it is.

AI can certainly be useful for this later task, but it'd be far preferable to just start there, as a form of pair-programming. And at that point, I doubt it'd be so interesting to say “built with ‹whatever model is popular today›” in the title.

iLoveOncall|1 year ago

Seems to mean "negative-acknowledgement" if like me you've never seen this abbreviation used before.

And yeah I agree.