{"id":23978493,"url":"https://github.com/simmsb/bad-datalog","last_synced_at":"2025-04-14T02:04:18.664Z","repository":{"id":94007260,"uuid":"378806071","full_name":"simmsb/bad-datalog","owner":"simmsb","description":"Some sort of datalog database","archived":false,"fork":false,"pushed_at":"2024-06-05T11:43:19.000Z","size":28,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-05T13:24:09.717Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simmsb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-21T04:28:55.000Z","updated_at":"2024-06-05T11:43:22.000Z","dependencies_parsed_at":"2023-04-26T09:31:54.617Z","dependency_job_id":null,"html_url":"https://github.com/simmsb/bad-datalog","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simmsb%2Fbad-datalog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simmsb%2Fbad-datalog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simmsb%2Fbad-datalog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simmsb%2Fbad-datalog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simmsb","download_url":"https://codeload.github.com/simmsb/bad-datalog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232844814,"owners_count":18585276,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-07T08:18:23.344Z","updated_at":"2025-01-07T08:18:25.699Z","avatar_url":"https://github.com/simmsb.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple datalog database and query planner\n\nSomething I've been messing around with: Trying to implement a datalog database\nwith a query api similar to datomic.\n\nThe datalog implementation is pretty much the same as\n[datafrog](https://github.com/rust-lang/datafrog)'s implementation, but with\nsupport for file-backed databases.\n\n\n## Example\n\n```rust\nuse dlog::{Database, QueryBuilder, RHS, object};\nuse tempfile::tempdir;\n\nlet tmp = tempdir().unwrap();\nlet sled_db = sled::open(tmp.path()).unwrap();\n\nlet mut db = Database::from_sled(sled_db.clone());\n\nlet book_foo = db.add_object(\u0026object!(\n    book_name: \"foo\",\n    book_price: 100,\n));\n\nlet book_bar = db.add_object(\u0026object!(\n    book_name: \"bar\",\n    book_price: 101,\n));\n\nlet _book_baz = db.add_object(\u0026object!(\n    book_name: \"baz\",\n    book_price: 102,\n));\n\nlet book_blah = db.add_object(\u0026object!(\n    book_name: \"blah\",\n    book_price: 103,\n));\n\ndb.add_object(\u0026object!(\n    review_book: book_foo,\n    review_user: \"reviewer_0\",\n    review_score: 10,\n));\n\ndb.add_object(\u0026object!(\n    review_book: book_foo,\n    review_user: \"reviewer_1\",\n    review_score: 100,\n));\n\ndb.add_object(\u0026object!(\n    review_book: book_bar,\n    review_user: \"reviewer_0\",\n    review_score: 102,\n));\n\ndb.add_object(\u0026object!(\n    review_book: book_blah,\n    review_user: \"reviewer_1\",\n    review_score: 99,\n));\n\nlet mut builder = QueryBuilder::default();\n\nlet b = builder.binding();\nlet p = builder.binding();\nlet t = builder.binding();\nlet r = builder.binding();\nlet s = builder.binding();\n\nbuilder\n    .pattern(r, \"review_book\", RHS::Bnd(b))\n    .pattern(r, \"review_user\", RHS::Str(\"reviewer_0\"))\n    .pattern(r, \"review_score\", RHS::Bnd(s))\n    .pattern(b, \"book_name\", RHS::Bnd(t))\n    .pattern(b, \"book_price\", RHS::Bnd(p))\n    .filter(p, |p_v| p_v.i().unwrap() \u003e 100)\n    ;\n\nlet plan = builder.plan();\n\nfor row in results {\n    println!(\n        \"b: {}, p: {}, t: {}, r: {}, s: {}\",\n        row.fetch(b),\n        row.fetch(p),\n        row.fetch(t),\n        row.fetch(r),\n        row.fetch(s),\n    )\n}\n\n// b: 1, p: 101, t: bar, r: 6, s: 102\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimmsb%2Fbad-datalog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimmsb%2Fbad-datalog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimmsb%2Fbad-datalog/lists"}