Hacker News new | ask | show | jobs
by triangleman 2035 days ago
This looks great, and way more capable than simply "prototyping and testing" as you put it on your web site.

How did you get sqlite3 to index JSON? I don't see anything in the product that does that. I'm searching through your source code now but I don't see anything specific.

1 comments

Well yes it started off for prototyping and then I kept adding more features like JavaScript middleware and token validation... I have used it as a backend for quite a few private projects of mine.

Regarding indexing json... here's how I do it:

     proc createIndex*(store: Datastore, indexId, field: string) =
       let query = sql("CREATE INDEX json_index_$1 ON documents(json_extract(data, ?) COLLATE NOCASE) WHERE json_valid(data)" % [indexId])
       store.begin()
       store.db.exec(query, field)
       store.commit()
Basically, SQLite supports indexes in arbitrary expressions and so you can use it in conjunction with json_extract. In this case, field is an arbitrary json path.

I then added a REST API in LiteStore to create (JSON) indexes... in that way you can make your queries more performant based on the specific json documents that you store in the data store.