dpapathanasiou / simple-graph

This is a simple graph database in SQLite, inspired by "SQLite as a document database"
MIT License
1.4k stars 86 forks source link

Searching for nodes where query must match a value in an array in the body #17

Closed rajarshi closed 1 year ago

rajarshi commented 1 year ago

I'm looking to do something like this

from simple_graph_sqlite import database as db 
dbfile = "db.sqlite"

db.initialize(dbfile)

db.atomic(dbfile, db.add_node({'name': 'foo', 'type':['company', 'start-up']}, 1))
db.atomic(dbfile, db.add_node({'name': 'bar', 'type':['cat', 'apple']}, 1))

db.atomic(apple, db.find_nodes({'type': 'apple'}, db._search_like, db._search_starts_with))

But I don't think the last statement works

dpapathanasiou commented 1 year ago

Hi @rajarshi

You're right, the current search statements do not introspect the json object correctly; looking at the sqlite json docs, it seems that statement need to use json_each.value LIKE ... or json_tree.type IN ... instead.

I can tinker with this some more, to see how to introduce those; ideally, I'd like to include them as statements in the sql so they're usable by any programming language that supports sql bindings, rather than coming up with a python-specific solution.

rajarshi commented 1 year ago

Got it, thanks

dpapathanasiou commented 1 year ago

Hi @rajarshi

I've recently revamped the search functions for allow for this; see the test and the updated example for how it works now, using the search templates.