owoof

github crates.io docs.rs

A glorified query-builder inspired by Datomic that uses a datalog-like format for querying and modifying information around a SQLite database.

This is a pet project and probably shouldn't be used for anything serious.

This is implemented as a rust library. It is documented, you can read the source or maybe find the documentation published on docs.rs.

There are two rust executable targets. One provides a command-line-interface (as shown below) and another can be used for importing data from a csv file.

CLI

Compile this with cargo build using --features cli --bin cli.

The CLI can be used to initialize new database files, assert/create, retract/remove, or query information.

Here are some examples:

```shell $ echo '[{":db/attribute": ":pet/name"}, {":pet/name": "Garfield"}, {":pet/name": "Odie"}, {":pet/name": "Spot"}, {":db/attribute": ":person/name"}, {":db/attribute": ":person/starship"}, {":person/name": "Jon Arbuckle"}, {":person/name": "Lieutenant Commander Data", ":person/starship": "USS Enterprise (NCC-1701-D)"}]' \ | owoof assert [ "#45e9d8e9-51ea-47e6-8172-fc8179f8fbb7", "#4aa95e29-8d45-470b-98a7-ee39aae1b9c9", "#2450b9e6-71a4-4311-b93e-3920eebb2c06", "#c544251c-a279-4809-b9b6-7d3cd68d2f2c", "#19a4cba1-6fc7-4904-ad36-e8502445412f", "#f1bf032d-b036-4633-b6f1-78664e44603c", "#e7ecd66e-222f-44bc-9932-c778aa26d6ea", "#af32cfdb-b0f1-4bbc-830f-1eb83e4380a3" ]

$ echo '[{":db/attribute": ":pet/owner"}, {":db/id": "#4aa95e29-8d45-470b-98a7-ee39aae1b9c9", ":pet/owner": "#e7ecd66e-222f-44bc-9932-c778aa26d6ea"}, {":db/id": "#2450b9e6-71a4-4311-b93e-3920eebb2c06", ":pet/owner": "#e7ecd66e-222f-44bc-9932-c778aa26d6ea"}, {":db/id": "#c544251c-a279-4809-b9b6-7d3cd68d2f2c", ":pet/owner": "#af32cfdb-b0f1-4bbc-830f-1eb83e4380a3"}]' \ | owoof assert [ "#ffc46ae2-1bde-4c08-bfea-09db8241aa2b", "#4aa95e29-8d45-470b-98a7-ee39aae1b9c9", "#2450b9e6-71a4-4311-b93e-3920eebb2c06", "#c544251c-a279-4809-b9b6-7d3cd68d2f2c" ]

$ owoof '?pet :pet/owner ?owner' \ --show '?pet :pet/name' \ --show '?owner :person/name' [ [ { ":pet/name": "Garfield" }, { ":person/name": "Jon Arbuckle" } ], [ { ":pet/name": "Odie" }, { ":person/name": "Jon Arbuckle" } ], [ { ":pet/name": "Spot" }, { ":person/name": "Lieutenant Commander Data" } ] ]

$ owoof '?person :person/starship "USS Enterprise (NCC-1701-D)"' \ '?pet :pet/owner ?person' \ '?pet :pet/name ?n' [ "Spot" ]

Or, suppose you know someone's name and their pet's name but don't know the attribute

that relates them... (But also this doesn't use indexes well so don't do it.)

$ owoof '?person :person/name "Lieutenant Commander Data"' \ '?pet ?owner ?person' \ '?pet :pet/name "Spot"' \ --show '?owner :db/attribute' [ { ":db/attribute": ":pet/owner" } ] ```

Imported from the goodbooks-10k dataset.

shell $ owoof '?r :rating/score 1' \ '?r :rating/book ?b' \ '?b :book/authors "Dan Brown"' \ --show '?r :rating/user' \ --show '?b :book/title' \ --limit 5 [ [ { ":rating/user": 9 }, { ":book/title": "Angels & Demons (Robert Langdon, #1)" } ], [ { ":rating/user": 58 }, { ":book/title": "The Da Vinci Code (Robert Langdon, #2)" } ], [ { ":rating/user": 65 }, { ":book/title": "The Da Vinci Code (Robert Langdon, #2)" } ], [ { ":rating/user": 80 }, { ":book/title": "The Da Vinci Code (Robert Langdon, #2)" } ], [ { ":rating/user": 89 }, { ":book/title": "The Da Vinci Code (Robert Langdon, #2)" } ] ]

Importing goodbooks-10k

  1. Initialize an empty database. shell $ owoof init

  2. Import books & --output a copy of the data with the :db/id column for each imported row. ```shell $ owoof-csv --output -- \ :book/title \ :book/authors \ :book/isbn \ :book/avg-rating\ average_rating \ < goodbooks-10k/books.csv \

    /tmp/imported-books ```

  3. Import ratings, we're using mlr to join the ratings with the imported books. shell $ mlr --csv join \ -f /tmp/imported-books \ -j book_id \ < goodbooks-10k/ratings.csv \ | owoof-csv -- \ ':rating/book :db/id' \ ':rating/score rating' \ ':rating/user user_id'

  4. That takes some time (probably minutes) but then you can do something like. shell $ owoof '?calvin :book/title "The Complete Calvin and Hobbes"' \ '?rating :rating/book ?calvin' \ '?rating :rating/score 1' \ '?rating :rating/user ?u' \ '?more-great-takes :rating/user ?u' \ '?more-great-takes :rating/book ?b' \ '?more-great-takes :rating/score 5' \ --show '?b :book/title :book/avg-rating' \ --asc '?b :book/avg-rating' And it should spit out some answers.

TODO/Caveats

Internal TODOs

See Also

My blog post associated with version 0.1 this software: https://froghat.ca/blag/dont-woof

License

This is licensed under Apache License, Version 2.0.