{"id":16187329,"url":"https://github.com/fiatjaf/levelup-js","last_synced_at":"2025-04-07T13:28:07.342Z","repository":{"id":75623823,"uuid":"86198424","full_name":"fiatjaf/levelup-js","owner":"fiatjaf","description":"https://www.npmjs.com/levelup bindings for gopherjs and adapter for https://github.com/fiatjaf/levelup","archived":false,"fork":false,"pushed_at":"2017-04-26T14:39:46.000Z","size":453,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-13T16:18:40.915Z","etag":null,"topics":["gopherjs-bindings"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fiatjaf.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}},"created_at":"2017-03-26T00:57:13.000Z","updated_at":"2018-02-27T00:26:51.000Z","dependencies_parsed_at":"2023-07-15T08:31:35.417Z","dependency_job_id":null,"html_url":"https://github.com/fiatjaf/levelup-js","commit_stats":null,"previous_names":["fiatjaf/go-levelup-js"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiatjaf%2Flevelup-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiatjaf%2Flevelup-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiatjaf%2Flevelup-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiatjaf%2Flevelup-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fiatjaf","download_url":"https://codeload.github.com/fiatjaf/levelup-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247660004,"owners_count":20974820,"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":["gopherjs-bindings"],"created_at":"2024-10-10T07:21:28.940Z","updated_at":"2025-04-07T13:28:07.319Z","avatar_url":"https://github.com/fiatjaf.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GoDoc](https://godoc.org/github.com/fiatjaf/go-levelup-js?status.png)](http://godoc.org/github.com/fiatjaf/go-levelup-js) [![travis ci badge](https://travis-ci.org/fiatjaf/levelup-js.svg?branch=master)](https://travis-ci.org/fiatjaf/levelup-js)\n\n# levelup bindings for gopherjs\n\nThis package implements the [levelup](https://github.com/fiatjaf/levelup) interface, and at the same time wraps https://www.npmjs.com/package/levelup so you can use any of the [supported leveldown backends](https://github.com/Level/levelup/wiki/Modules#storage-back-ends).\n\n## how to use\n\n```go\npackage main\n\nimport (\n\t\"github.com/fiatjaf/go-levelup\"\n\t\"github.com/fiatjaf/go-levelup-js\"\n\t\"github.com/fiatjaf/levelup/stringlevelup\"\n)\n\nfunc main() {\n\tbdb := levelupjs.NewDatabase(\"my-beautiful-browser-database\", \"fruitdown\")\n\tdefer bdb.Erase()\n\n\tdb := stringlevelup.StringDB(bdb)\n\n\tfmt.Println(\"setting key1 to x\")\n\tdb.Put(\"key1\", \"x\")\n\tres, _ := db.Get(\"key1\")\n\tfmt.Println(\"setting key2 to 2\")\n\tfmt.Println(\"res at key2: \", res)\n\tdb.Put(\"key2\", \"y\")\n\tres, _ = db.Get(\"key2\")\n\tfmt.Println(\"res at key2: \", res)\n\tfmt.Println(\"deleting key1\")\n\tdb.Del(\"key1\")\n\tres, _ = db.Get(\"key1\")\n\tfmt.Println(\"res at key1: \", res)\n\n\tfmt.Println(\"batch\")\n\tdb.Batch([]levelup.Operation{\n\t\tstringlevelup.Put(\"key2\", \"w\"),\n\t\tstringlevelup.Put(\"key3\", \"z\"),\n\t\tstringlevelup.Del(\"key1\"),\n\t\tstringlevelup.Put(\"key1\", \"t\"),\n\t\tstringlevelup.Put(\"key4\", \"m\"),\n\t\tstringlevelup.Put(\"key5\", \"n\"),\n\t\tstringlevelup.Del(\"key3\"),\n\t})\n\tres, _ = db.Get(\"key1\")\n\tfmt.Println(\"res at key1: \", res)\n\tres, _ = db.Get(\"key2\")\n\tfmt.Println(\"res at key2: \", res)\n\tres, _ = db.Get(\"key3\")\n\tfmt.Println(\"res at key3: \", res)\n\n\tfmt.Println(\"reading all\")\n\titer := db.ReadRange(nil)\n\tfor ; iter.Valid(); iter.Next() {\n\t\tfmt.Println(\"row: \", iter.Key(), \" \", iter.Value())\n\t}\n\tfmt.Println(\"iter error: \", iter.Error())\n\titer.Release()\n```\n\nif you don't call `stringlevelup.StringDB` on the object returned by `NewDatabase` you still can use the same methods, only replacing all `string` arguments with `[]byte` (returned values will also be bytes). I've just used the string approach here for readability, but it is slower.\n\n`levelupjs` will try to `require()` both `levelup` and the name of the adapter you gave. If `require` is not available it will try to load these from the global namespace, so `window.levelup` and `window[adapterName]` must be set. If you're running this on a Node.js environment you should be fine with the above instructions, but if you're just using raw HTML you'll have to include these dependencies before, like:\n\n## How to use:\n\n### plain browser \u003cscript\u003e\n\nYou can just include `levelup` and the adapter of your choice. They will be picked from the global namespace.\n\n```html\n\u003c!doctype html\u003e\n\n\u003cscript src=https://wzrd.in/standalone/levelup\u003e\u003c/script\u003e\n\u003cscript src=https://wzrd.in/standalone/fruitdown\u003e\u003c/script\u003e\n\u003cscript src=your-script-that-includes-levelupjs-somehow.js\u003e\u003c/script\u003e\n```\n\nIf you're using Webpack, this is probably what you have to do.\n\n### [browserify](http://browserify.org/)\n\nFor the JS libraries to be available for being required from the GopherJS environment they must be \"globally\" requireable, that's not possible if you do the normal browserifying stuff, but it is if you bundle them the following way:\n\n```shell\ngo get github.com/fiatjaf/go-levelup-js\nnpm install levelup\nnpm install fruitdown # or other adapter, you probably want 'memdown' for testing.\nbrowserify your-script.js -r levelup -r memdown -o bundle.js\n```\n\nThen include `bundle.js` in the HTML.\n\n### standalone program (backed by Node.js)\n\n```shell\ngo get github.com/fiatjaf/go-levelup-js\nnpm install levelup\nnpm install fruitdown # or other adapter, you probably want 'memdown' for testing.\ngopherjs run your-script.go\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffiatjaf%2Flevelup-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffiatjaf%2Flevelup-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffiatjaf%2Flevelup-js/lists"}