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

support a uuid as node.id #3

Closed lepy closed 3 years ago

lepy commented 3 years ago

uuid.UUID('5b86cc504bda4c7e94d47d00a7696bde').int

P.S. Thank you for your work. This library has made my day.

dpapathanasiou commented 3 years ago

Hi @lepy

Thank you for creating this pull request, there are many good ideas here that I'd like to incorporate, such as the tests.

As for the core premise though, note that you don't need any special code support for using uuids as primary keys.

Instead of using the integers as primary keys, it's also possible to do this instead:

>>> from uuid import uuid4
>>> one = uuid4()

and then uuid as string:

>>> db.atomic(apple, 
db.add_node({'name': 'Apple Computer Company', 'type':['company', 'start-up'], 'founded': 'April 1, 1976'}, 
str(one)))

or uuid as integer:

>>> db.atomic(apple, 
db.add_node({'name': 'Apple Computer Company', 'type':['company', 'start-up'], 'founded': 'April 1, 1976'}, 
one.int))

or even uuid as hex code:

>>> db.atomic(apple, 
db.add_node({'name': 'Apple Computer Company', 'type':['company', 'start-up'], 'founded': 'April 1, 1976'}, 
one.hex))
lepy commented 3 years ago

Hi dpapathanasiou,

I can't reproduce the uuid error right now, but an index with an int64 threw an error on another machine with Python 3.7.4. May be it was a Python 3.6 issue.

What do you think about implementing it as a class?

https://github.com/lepy/simple-graph/blob/main/simple_graph_db/__init__.py

db = Database(db_file="db_file")
db.add_node(data={"a":1}, identifier='85831b3f0b284d18b57cb10534701cc2')
db.add_node(data={"b":1}, identifier='b5831b3f0b284d18b57cb10534701cc2')
db.find_node('85831b3f0b284d18b57cb10534701cc2')
db.connect_nodes('85831b3f0b284d18b57cb10534701cc2', 'b5831b3f0b284d18b57cb10534701cc2', {'o': 2})

Do you plan to publish the code on pipy? What package name will you use there?

Best wishes

Lepy

dpapathanasiou commented 3 years ago

Hi @lepy

What do you think about implementing it as a class?

https://github.com/lepy/simple-graph/blob/main/simple_graph_db/__init__.py

That's interesting!

I admit to thinking of Python in more functional terms, but there are some advantages to grouping it in a class like that.

I'll try to incorporate some of those ideas in the next release.

Do you plan to publish the code on pipy? What package name will you use there?

Yes, I did that earlier today (plain "simple-graph" was already taken, alas):

https://pypi.org/project/simple-graph-sqlite/

Note that if you install it from there, you'll need to use that prefix in your imports:

from simple_graph_sqlite import database as db
dpapathanasiou commented 3 years ago

Hi, I'm closing this, as the structure of the repo has changed quite a bit since you posted this originally.

I did incorporate many of your ideas, though, and the package is now available on pypi, if you'd rather install it that way (you can follow the changes there on this meta repo).

P.S. I'm launching a modified version of this project as a cloud-based service. Let me know if you'd be interested in being a (free) trial user.