{"id":13646528,"url":"https://github.com/nicferrier/emacs-db","last_synced_at":"2025-09-13T07:26:55.312Z","repository":{"id":4774486,"uuid":"5926105","full_name":"nicferrier/emacs-db","owner":"nicferrier","description":"very simple database for emacslisp, can also wrap other databases.","archived":false,"fork":false,"pushed_at":"2017-01-18T21:48:50.000Z","size":167,"stargazers_count":56,"open_issues_count":6,"forks_count":14,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-03T18:44:28.218Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Emacs Lisp","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nicferrier.png","metadata":{"files":{"readme":"README.creole","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-09-23T20:52:24.000Z","updated_at":"2022-10-14T19:13:43.000Z","dependencies_parsed_at":"2022-09-01T05:40:35.074Z","dependency_job_id":null,"html_url":"https://github.com/nicferrier/emacs-db","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nicferrier/emacs-db","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicferrier%2Femacs-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicferrier%2Femacs-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicferrier%2Femacs-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicferrier%2Femacs-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nicferrier","download_url":"https://codeload.github.com/nicferrier/emacs-db/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicferrier%2Femacs-db/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265524624,"owners_count":23782013,"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":"2024-08-02T01:02:58.244Z","updated_at":"2025-07-16T16:32:12.460Z","avatar_url":"https://github.com/nicferrier.png","language":"Emacs Lisp","funding_links":[],"categories":["Emacs Lisp"],"sub_categories":[],"readme":"= Emacs Db - Key/Values stores for Emacs =\n\nAn EmacsLisp interface to key/value stores (Mongo, Postgresql Hstore,\netc..) with a simple default implementation based on EmacsLisp Hashtables.\n\n== The interface ==\n\nThe idea behind this is to make an interface for interacting with\nsimple key/value database stores that is portable across all such\nstores. So you can make code once but swap out the database with\nrelative ease.\n\nThe interface includes the following functions:\n\n=== db-make reference ===\n\nMake a DB based on the //reference//.\n\n=== db-get key db ===\n\nGet the value from the //db// with the //key//.\n\n=== db-put key value db ===\n\nPut a new //value// into the //db// with the specified //key//.\n\nReturn the //value// as it has been put into the //db//.\n\n=== db-map func db \u0026optional query filter ===\n\nCall //func// for every record in //db// optionally //query// filter.\n\n//query//, if specified, should be a list of query terms.\n\n//func// should take 2 arguments:\n\n{{{\n  key db-value\n}}}\n\nwhere the DB-VALUE is whatever the //db// has attached to the\nspecified KEY.\n\nThis returns an alist of the KEY and the value the function\nreturned.  If //filter// is [[t]] then only pairs with a value are\nreturned.\n\n=== db-query db query ===\n\nDo //query// on //db// and return the result.\n\nThis is [[db-map]] with an identity function.\n\n\n== Query language ==\n\n{{{db}}} uses the query language provided by the {{{kv}}} library,\nwhich is implemented as a mapping function test on ever value by the\npersistent hashtable implementation.\n\nThe language should be translatable to just about any database query\nlanguage (Mongo, SQL, etc...).\n\nThere are only 3 constructs currently, {{{|}}}, {{{\u0026}}} and {{{=}}}.\n\nAn expression could be:\n\n{{{\n(= field-name value)\n}}}\n\nTo select any record where {{{field-name}}} has the {{{value}}}\n\n{{{\n(|(= field-name value)(= other-field other-value))\n}}}\n\nTo select any record where {{{field-name}}} has the {{{value}}} \nor {{{other-field}}} has the value {{{other-value}}}\n\n{{{\n(\u0026(= field-name value)(= other-field other-value))\n}}}\n\nTo select any record where {{{field-name}}} has the {{{value}}} \nand {{{other-field}}} has the value {{{other-value}}}.\n\nLogical combinations of {{{|}}} and {{{\u0026}}} are also possible.\n\n\n== Hashtable implementation ==\n\n{{{db}}} comes with a simple implementation which can store any\nEmacsLisp object (though alists would most usually be preferred).\n\nTo make a {{{db}}} with the hash implementation:\n\n{{{\n(db-make \n  `(db-hash \n     :filename ,(format \"/var/cache/some-file\")))\n}}}\n\nObviously, most often you will assign the db to a global variable.\n\n{{{\n(defvar my-db \n  (db-make \n   `(db-hash \n     :filename ,(format \"/var/cache/some-file\"))))\n\n(db-put \"001\" '((\"a\" . 10)(\"b\" . 20)) my-db)\n(db-put \"002\" '((\"a\" . 17)(\"b\" . \"hello\")(\"xyz\" . \"well!\")) my-db)\n(db-get \"002\" my-db)\n}}}\n\nresults in:\n\n{{{\n((\"a\" . 17)(\"b\" . \"hello\")(\"xyz\" . \"well!\"))\n}}}\n\n=== Testing ===\n\nHash Db's are tied to filenames so to test them you often have to\nmanage that persistence:\n\n{{{\n(unwind-protect\n     (let ((mydb (db-make `(db-hash :filename \"/tmp/mydb\")))\n           (json \n             (with-temp-buffer\n              (insert-file-contents \"~/work/elmarmalade/users-mongo.json\")\n              (goto-char (point-min))\n              (json-read))))\n       (--each json (db-put (car it) (cdr it) mydb))\n       (list (db-get 'triss mydb)\n             (db-get 'nicferrier mydb)))\n  (delete-file \"/tmp/mydb.elc\"))\n}}}\n\nNote the deleting of the {{{elc}}} file. That's how the hash db is\nstored. \n\nAlternately one could use {{{fakir-file}}} (see the fakir package) to\nmock the file system. But that's harder than just creating and\nthrowing away the file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicferrier%2Femacs-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicferrier%2Femacs-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicferrier%2Femacs-db/lists"}