{"id":14956931,"url":"https://github.com/samuelscheit/lambert-orm","last_synced_at":"2025-04-07T11:44:49.954Z","repository":{"id":138371596,"uuid":"322245177","full_name":"SamuelScheit/Lambert-orm","owner":"SamuelScheit","description":"A Database abstraction layer for different DB Engines","archived":false,"fork":false,"pushed_at":"2023-07-19T11:10:27.000Z","size":509,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-05-01T19:33:55.833Z","etag":null,"topics":["abstraction","database","mongodb","orm"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/SamuelScheit.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":"2020-12-17T09:30:09.000Z","updated_at":"2024-07-29T22:24:45.741Z","dependencies_parsed_at":null,"dependency_job_id":"6ea7dacc-7596-4e06-94aa-c21da537eb0f","html_url":"https://github.com/SamuelScheit/Lambert-orm","commit_stats":null,"previous_names":["trenite/lambert-db"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamuelScheit%2FLambert-orm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamuelScheit%2FLambert-orm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamuelScheit%2FLambert-orm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamuelScheit%2FLambert-orm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SamuelScheit","download_url":"https://codeload.github.com/SamuelScheit/Lambert-orm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247648928,"owners_count":20972942,"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":["abstraction","database","mongodb","orm"],"created_at":"2024-09-24T13:13:45.294Z","updated_at":"2025-04-07T11:44:49.894Z","avatar_url":"https://github.com/SamuelScheit.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lambert-db\nA Database abstraction layer for different DB Engines\n\nThis allows easy access to a database much like like accessing an object.\n\nThe library design facilitates exchanging the underlying database engine without changing your application code.\n\nAlso it only get's/set's the necessary data for the operations and not the whole table unlike quick.db.\n\n## Installation\n```\nnpm i lambert-db\n# or \"yarn add lambert-db\"\n```\n\n## Usage\nES5 import\n\n```js\nrequire(\"lambert-db\");\n```\nor ES6 import\n\n```js\nimport \"lambert-db\";\n```\n\n## Database\nChoose a database engine: ``MongoDatabase``\n\nAt the moment there is only an implementation for MongoDB available, however I will add others.\nYou can also implement your own database class and submit a pull request.\n\nEvery Database has an ``.init()`` method whose execution must be awaited before using the database.\n```ts\nclass Database {\n    init   (): Promise\u003cany\u003e;\n    destroy(): Promise\u003cany\u003e;\n    data     : DatastoreInterface; // ES6 Proxy Object\n}\n```\nTo use the database, access the ``.data`` property and specify the path.\n#### Example\n```js\ndb.data.users.name // (the path for this example is users.name). \n``` \nThe below operations can then be called on the path:\n\n## Operations\n\n```ts\nget(projection?: Projection): Promise\u003cany\u003e; // returns a promise with the value for this path\nfirst()                     : Promise\u003cany\u003e; // returns a promise with the first entry\nlast()                      : Promise\u003cany\u003e; // returns a promise with the last entry\nrandom()                    : Promise\u003cany\u003e; // returns a promise with a random entry \ndelete()                    : Promise\u003cboolean\u003e; // deletes the value for this path\nset(value: any)             : Promise\u003cboolean\u003e; // sets the value for this path\nexists()                    : Promise\u003cboolean\u003e; // checks if a value for this path exists\npush(value: any)            : Promise\u003cboolean\u003e; // pushes the value into the array for this path\n```\nAll operations are asynchronous and return a [promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) which have to be awaited.\nThe return value of type ``Promise\u003cboolean\u003e`` indicates a successful operation.\n#### Example\n```js\nawait db.data.users.push({id: 1, name: \"test\", posts: [1,2,3] }) // this will insert this user object\nawait db.data.users.name.set(\"hello\") // this will set the name hello for all users\nawait db.data.users.name.get() // this will return an array with the users names\nawait db.data.users.delete() // this will delete all users\n```\n\n### Projection\nThe ``.get(projection?: Projection)`` function can optionally accept a projection parameter.\n\nA Projection is a Key-Value Object of booleans that indicates whether these properties should be received. \n```ts\ntype Projection = {\n    [index: string]: boolean;\n};\n\nvar projection = { id: true, name: true}\n```\n\nFor example, a database with a ``boards`` table that contains  board objects like: ``{ id: number, name: string, members: [], posts: [] }`` and only ids and names should be accessed. \n\nThe projection parameters can be used to specify multiple but not all properties to be retrieved e.g:\n```js\nawait db.data.boards.get({ id: true, name: true}); // This will only return the id and name of the boards\n```\n\n### Filter sub arrays\n\nFilters can be used to get a specific card in the example above, by calling a property with ``.property(filter)`` when accessing a path.\n\nA filter can be an object or a function which will be called for every entry in an array and can be specified for each property in a path.\n\n#### Example:\n```js\nawait db.data.boards({id: 1}).get() // This will return the board with id: 1 and insert \nawait db.data.boards({id: 1}).posts({id: 0}).comments.push({author: 1, content: \"test\"}) // This will post a comment to board.id: 1 and post.id: 0\n```\n\n\n## Full Example\n```js\nconst { MongoDatabase } = require(\"lambert-db\");\n\nconst db: Database = new MongoDatabase();\n\ndb.init().then(async () =\u003e {\n\tlet success = await db.data.users.push({ id: 0, roles: [] });\n\tif (!success) throw new Error(\"couldn't insert new user\");\n\n\tlet user = await db.data.users({ id: 0 }).get();\n\tconsole.log(user);\n\t\n\tsuccess = await db.data.users({ id: 0 }).roles.push({ type: \"admin\", name: \"test\", permissions: 2 });\n\tif (!success) throw new Error(\"couldn't add role for user\");\n\n\tconsole.log(await db.data.users.get({ id: true}));\n\t\n\tsuccess = await db.data.users({ id: 1 }).delete();\n\tif (!success) throw new Error(\"couldn't delete user\");\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamuelscheit%2Flambert-orm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamuelscheit%2Flambert-orm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamuelscheit%2Flambert-orm/lists"}