{"id":21840478,"url":"https://github.com/rubiojr/kv","last_synced_at":"2025-04-14T10:51:33.310Z","repository":{"id":38205681,"uuid":"468539542","full_name":"rubiojr/kv","owner":"rubiojr","description":"Simple key-value store on top of SQLite or MySQL","archived":false,"fork":false,"pushed_at":"2025-03-24T18:08:49.000Z","size":149,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-28T00:04:56.588Z","etag":null,"topics":["database","key-value","mysql","sqlite"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rubiojr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2022-03-10T23:11:58.000Z","updated_at":"2024-05-14T13:20:42.000Z","dependencies_parsed_at":"2024-03-26T19:52:06.314Z","dependency_job_id":"f74d9c8d-bb48-401a-b933-b5403e7711bd","html_url":"https://github.com/rubiojr/kv","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubiojr%2Fkv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubiojr%2Fkv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubiojr%2Fkv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubiojr%2Fkv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rubiojr","download_url":"https://codeload.github.com/rubiojr/kv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248868858,"owners_count":21174754,"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":["database","key-value","mysql","sqlite"],"created_at":"2024-11-27T21:26:28.172Z","updated_at":"2025-04-14T10:51:33.290Z","avatar_url":"https://github.com/rubiojr.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KV\n\nA simple key/value store on top of SQLite or MySQL (Go port of [GitHub's KV](https://github.com/github/github-ds/blob/master/lib/github/kv.rb)).\n\nAims compatible with the original implementation by default, offering a few extra backend drivers and some extra configuration knobs.\n\n## Status\n\nWork in progress.\n\n* Drivers are almost feature complete.\n* No optmization work has happened yet.\n* Both drivers could use a few extra tests.\n* API changes not expected at this point.\n* Not SQL injection free\n\nMissing functionality:\n\n- [ ] Custom driver options for MySQL and SQLite\n- [ ] setnx\n- [ ] increment\n- [ ] ttl\n- [ ] mttl\n- [ ] Configurable key/value max length\n- [ ] Enforce default key and value max length\n\n## Initialization \n\nImport the module first:\n\n```Go\nimport \"github.com/rubiojr/kv\"\n```\n\n### MySQL\n\n```Go\ndb, err := kv.New(\"mysql\", \"root:toor@tcp(127.0.0.1:3306)/gokv\")\n```\n\nNote that the database `gokv` and the table name used by default `key_values` will need to be created before using this driver.\n\n```sql\nUSE gokv\nCREATE TABLE IF NOT EXISTS key_values (\n\t\t\t`id` bigint(20) NOT NULL AUTO_INCREMENT,\n\t\t\t`key` varchar(255) NOT NULL,\n\t\t\t`value` blob NOT NULL,\n\t\t\t`created_at` datetime NOT NULL,\n\t\t\t`updated_at` datetime NOT NULL,\n\t\t\t`expires_at` datetime DEFAULT NULL,\n\t\t\tPRIMARY KEY (id),\n\t\t\tUNIQUE KEY index_key_values_on_key (`key`),\n\t\t\tKEY index_key_values_on_expires_at (expires_at)\n\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8\n```\n\n### SQLite\n\n```Go\ndb, err := kv.New(\"sqlite\", \"my.db\")\n```\n\nCreates a `key_values` table in `my.db` file database to store key/values.\n\n## Getting and setting keys\n\nSingle keys:\n\n```Go\n// set a couple of keys\nerr = db.Set(\"foo\", []byte(\"bar\"), nil)\nif err != nil {\n\tpanic(err)\n}\nerr = db.Set(\"stuff\", []byte(\"staff\"), nil)\nif err != nil {\n\tpanic(err)\n}\n\n// Get one key\nv, err := db.Get(\"foo\")\nif err != nil {\n\tpanic(err)\n}\nfmt.Println(string(v)) // prints bar\n\n// Deleting a single key\nerr := db.Del(\"foo\")\nif err != nil {\n\tpanic(err)\n}\n```\n\nMultiple keys:\n\n```Go\n// Get multiple keys\nvalues, err := db.MGet(\"foo\", \"staff\")\nif err != nil {\n\tpanic(err)\n}\n// iterate the results\nfor _, v := range values {\n\tfmt.Println(string(v))\n}\n\n// Set multiple keys\nvalues := types.KeyValues{}\nvalues[\"mset1\"] = \"msetv1\"\nvalues[\"mset2\"] = \"msetv2\"\nerr = db.MSet(values, nil)\n\n// Deleting multiple keys\nerr := db.MDel(\"mset1\", \"mset2\")\nif err != nil {\n\tpanic(err)\n}\n\n```\n\n### Storing binary values\n\nAn example using [vmihailenco/msgpack](https://github.com/vmihailenco/msgpack) to serialize data.\n\n```Go\n// store a string as a binary blob\nb, err := msgpack.Marshal(\"blob\")\nif err != nil {\n\tpanic(err)\n}\n\nerr = db.Set(\"bin\", b, nil)\nif err != nil {\n\tpanic(err)\n}\n\nv, err = db.Get(\"bin\")\nif err != nil {\n\tfmt.Println(err)\n}\n\nvar blobStr string\nerr = msgpack.Unmarshal(b, \u0026blobStr)\nif err != nil {\n\tpanic(err)\n}\nfmt.Println(blobStr)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubiojr%2Fkv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubiojr%2Fkv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubiojr%2Fkv/lists"}