{"id":17950042,"url":"https://github.com/ciscoheat/haxelow","last_synced_at":"2025-03-24T23:32:06.105Z","repository":{"id":33961366,"uuid":"37693692","full_name":"ciscoheat/haxelow","owner":"ciscoheat","description":"A small, flat JSON database library for Haxe.","archived":false,"fork":false,"pushed_at":"2016-06-29T21:55:21.000Z","size":28,"stargazers_count":35,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-19T05:24:57.853Z","etag":null,"topics":["database","haxe","json","lowdb"],"latest_commit_sha":null,"homepage":"","language":"Haxe","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/ciscoheat.png","metadata":{"files":{"readme":"README.md","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":"2015-06-19T00:55:53.000Z","updated_at":"2024-01-05T00:19:14.000Z","dependencies_parsed_at":"2022-07-13T16:00:43.086Z","dependency_job_id":null,"html_url":"https://github.com/ciscoheat/haxelow","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/ciscoheat%2Fhaxelow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ciscoheat%2Fhaxelow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ciscoheat%2Fhaxelow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ciscoheat%2Fhaxelow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ciscoheat","download_url":"https://codeload.github.com/ciscoheat/haxelow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245372193,"owners_count":20604487,"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","haxe","json","lowdb"],"created_at":"2024-10-29T09:36:54.293Z","updated_at":"2025-03-24T23:32:05.818Z","avatar_url":"https://github.com/ciscoheat.png","language":"Haxe","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HaxeLow\n\nA Haxe port of [lowdb](https://github.com/typicode/lowdb) which is a flat JSON file database.\n\n## How to use\n\n`haxelib install haxelow`, then put `-lib haxelow` in your `.hxml` file.\n\n**For Node.js:** Define `-D nodejs` or use `-lib hxnodejs`. The npm packages `steno` and `graceful-fs` are required.\n\n**In the browser, or for `Sys` targets:** It works straight out-of-the-box.\n\n## Example\n\n```haxe\nclass Person {\n\tpublic function new(name, birth) {\n\t\tthis.name = name; this.birth = birth;\n\t}\n\n\tpublic var name : String;\n\tpublic var birth : Int;\n}\n\nclass Main {\n\tstatic function main() {\n\t\t// Create the database\n\t\tvar db = new HaxeLow('db.json');\n\n\t\t// Get a collection of a class\n\t\tvar persons = db.col(Person);\n\n\t\t// persons is now an Array\u003cPerson\u003e\n\t\t// that can be manipulated as you like\n\t\tpersons.push(new Person(\"Test\", 1977));\n\n\t\t// Save all collections to disk.\n\t\t// This is the only way to save, no automatic saving\n\t\t// takes place.\n\t\tdb.save();\n\t}\n}\n```\n\nThis is nice and simple, but wait, there's more! You can use any field in your class as an ID field:\n\n```haxe\nclass Person {\n    public function new(name, birth) {\n        this.name = name; this.birth = birth;\n    }\n\n    // Easy way to generate a v4 UUID:\n    public var id : String = HaxeLow.uuid();\n    public var name : String;\n    public var birth : Int;\n}\n\nclass Main {\n    static function main() {\n        var db = new HaxeLow('db.json');\n\n        // If your id field is named id, use idCol instead of col:\n        var persons = db.idCol(Person);\n\n        var person = new Person(\"Test\", 1978);\n\n        // And you have some useful 'id' methods on the collection\n        // (it still works as an array too)\n        persons.idInsert(person); // returns true\n\n        // Inserting person with same id will return false\n        persons.idInsert(person); // false\n\n        // Update the person entry\n        persons.idUpdate(person.id, { birth: 1979 });\n\n        // idReplace will replace if same id, insert otherwise\n        var anotherPerson = new Person(\"Test2\", 1980);\n        anotherPerson.id = person.id;\n        persons.idReplace(anotherPerson); // true\n\n        // Remember to save!\n        db.save();\n    }\n}\n```\n\nIf your id field is named `_id`, use the method `db._idCol(Person)`, or you can use `db.keyCol(Person, idFieldName)` for any field.\n\n## In-memory and browser DB\n\nIf you don't pass a filename when creating a `HaxeLow` object, it will be in-memory only. For the browser, if you pass a filename, HaxeLow will save the data in localStorage with the same key as the filename.\n\n## When to use HaxeLow\n\nStraight from the lowdb docs:\n\nHaxeLow/lowdb is a convenient method for storing data without setting up a database server. It's fast enough and safe to be used as an embedded database.\n\nHowever, if you need high performance and scalability more than simplicity, you should stick to databases like MongoDB.\n\n## API reference\n\n`var db = new HaxeLow(?filename : String)` - Creates the HaxeLow database. If no filename is specified, an in-memory DB is created.\n\n`HaxeLow.uuid()` - Generates a v4 UUID where the first four bytes are the timestamp, so the generated id's can be sorted easily.\n\n`db.col\u003cT\u003e(cls : Class\u003cT\u003e)` - Returns an `Array\u003cT\u003e` for a class.\n\n`db.idCol\u003cT, K\u003e(cls : Class\u003cT\u003e, ?keyType : Class\u003cK\u003e)` - Returns an `Array\u003cT\u003e` with extra id methods, for classes with an `id : K` field.\n\n`db._idCol\u003cT, K\u003e(cls : Class\u003cT\u003e, ?keyType : Class\u003cK\u003e)` - Returns an `Array\u003cT\u003e` with extra id methods, for classes with an `_id : K` field.\n\n`db.keyCol\u003cT, K\u003e(cls : Class\u003cT\u003e, keyField : String, ?keyType : Class\u003cK\u003e)` - Returns an `Array\u003cT\u003e` with extra id methods, for any `keyField : K` that exists on a class.\n\n`db.backup(?file : String)` - Returns the DB as a JSON `String`. If `file` is specified, the DB is saved to that file.\n\n`db.restore(s : String)` - Restores the DB based on a JSON `String`, but as with other operations, does not save the DB automatically.\n\n`db.save()` - Saves the DB to disk. (Does nothing for in-memory DB's)\n\n`db.file` - Filename for the current DB.\n\n## Making it work everywhere\n\nThe ways to store the DB varies a lot between platforms, so the only real solution is to let people implement their own disk storage. HaxeLow uses a simple interface for that, `HaxeLow.HaxeLowDisk`:\n\n```haxe\ninterface HaxeLowDisk {\n\t// Read a file synchronously and return its contents.\n\tpublic function readFileSync(file : String) : String;\n\n\t// Write to a file async or sync, it's up to you.\n\tpublic function writeFile(file : String, data : String) : Void;\n}\n```\n\nWhen you have implemented this interface, just pass an instance of the implemented class as the second argument to `HaxeLow`:\n\n```haxe\nclass Main {\n\tstatic function main() {\n\t\tvar db = new HaxeLow('db.json', new YourDiskInterface());\n\t}\n}\n```\n\n## Credits\n\nHaxeLow uses [TJSON](https://github.com/martamius/TJSON), the tolerant JSON parser for Haxe.\n\nThanks to Frank Endres for some patches, and of course the lowdb authors for the whole idea!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fciscoheat%2Fhaxelow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fciscoheat%2Fhaxelow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fciscoheat%2Fhaxelow/lists"}