{"id":16387492,"url":"https://github.com/mastilver/lawson","last_synced_at":"2025-03-23T04:31:29.683Z","repository":{"id":72365749,"uuid":"49367656","full_name":"mastilver/lawson","owner":"mastilver","description":"Database agnostic ODM","archived":false,"fork":false,"pushed_at":"2017-04-10T08:44:37.000Z","size":35,"stargazers_count":4,"open_issues_count":6,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-19T15:03:28.341Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/mastilver.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":"2016-01-10T13:22:15.000Z","updated_at":"2022-03-03T01:21:43.000Z","dependencies_parsed_at":"2023-05-21T05:45:34.380Z","dependency_job_id":null,"html_url":"https://github.com/mastilver/lawson","commit_stats":{"total_commits":51,"total_committers":4,"mean_commits":12.75,"dds":"0.47058823529411764","last_synced_commit":"2dfc12d47b88bd110ec87b105493441757e4c110"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mastilver%2Flawson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mastilver%2Flawson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mastilver%2Flawson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mastilver%2Flawson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mastilver","download_url":"https://codeload.github.com/mastilver/lawson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245056889,"owners_count":20553855,"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-10-11T04:26:40.976Z","updated_at":"2025-03-23T04:31:29.300Z","avatar_url":"https://github.com/mastilver.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lawson [![Build Status](https://travis-ci.org/mastilver/lawson.svg?branch=master)](https://travis-ci.org/mastilver/lawson)\n\n\u003e Database agnostic ODM\n\n\n## Install\n\n```\n$ npm install --save lawson nosqwal-memory\n```\n\n\n## Setup\n\n`orm.js`\n```js\nimport nosqwal from 'nosqwal-memory';\nimport lawson from 'lawson';\n\nconst noSqwalInstance = noSqwal();\n\nexport const collection = lawson(noSqwalInstance).defineCollection;\n```\n\n`models/user.js`\n```js\nimport {collection} from '../orm';\n\nexport default collection('user', {\n    username: 'string',\n    email: 'string',\n    password: 'string'\n});\n```\n\n## Usage\n\n```js\nimport user from './models/user';\n\n/*   create   */\nuser.create({\n    username: 'test',\n    email: 'test@test.com',\n    password: 'secret'\n})\n/*   get   */\n.then(createdUser =\u003e {\n    return user.get(createdUser.id);\n})\n/*   update   */\n.then(newUser =\u003e {\n    newUser.username = 'bobby';\n\n    return user.update(newUser.id, newUser);\n})\n.then(updatedUser =\u003e {\n    console.log('user updated');\n})\n.then(() =\u003e {\n    return user.query({\n        where: {\n            username: 'bobby'\n        }\n    });\n})\n.then(users =\u003e {\n    console.log(user.length);\n    // =\u003e 1\n\n    return user.delete(users[0].id);\n})\n.catch(e =\u003e {\n    console.warn(e);\n});\n```\n\n\n## API\n\n### lawsonInstance = lawson(noSqwalInstance)\n\nCreate a new instance of lawson\n\n#### noSqwalInstance\n\nType: [Nosqwal instance](https://github.com/mastilver/nosqwal)  \n*required*\n\n### collection = lawsonInstance.defineCollection(collectionName, modelDefinition)\n\nDefine a new collection\n\n#### collectionName\n\nType: `string`  \n*required*\n\nthe name of the collection\n\n#### modelDefinition\n\nType: `object`\n*required*\n\nThe schema of the document, see its definition [here](https://github.com/mastilver/db-schema-validator#schema-definition)\n\n### collection.get(documentId)\n\nReturns a Promise, that resolve to the requested document\n\n#### documentId\n\nType: `string`  \n*required*\n\n### collection.update(document)\n\nReturns a Promise, that resolve when the document is updated\n\n#### document\n\nType: `object`\n*required*\n\nthe new version of the document that will be updated\n\n##### document.id\n\nType: `string`\n*required*\n\nthe id of the document to update\n\n### collection.create(document)\n\nReturns a Promise, that resolve to the created document\n\n#### document\n\nType: `object`\n*required*\n\nThe document that will be created\n\n### collection.delete(documentId)\n\nReturns a Promise when the document is deleted\n\n#### documentId\n\nType: `string`\n*required*\n\nThe id of the document that will be deleted\n\n### collection.query(options)\n\nReturns a Promise, that resolve to all the documents\n\n#### options.where\n\nType: `object`\n\nUsed to filter out results of the query\n\n#### options.limit\n\nType: `number`\n\nThe number of documents to return\n\n#### options.offset\n\nType: `number`  \ndefault: 0\n\nThe number of documents to skip\n\n### collection.first(where)\n\nLike query(), but return a promise for only one document\n\n#### where\n\nType: `object`\n\nUsed to filter out results of the query\n\n### collection.single(where)\n\nLike first(), but throws an error if there is more that one document that matches the where clause\n\n#### where\n\nType: `object`\n\nUsed to filter out results of the query\n\n## License\n\nMIT © [Thomas Sileghem](http://mastilver.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmastilver%2Flawson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmastilver%2Flawson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmastilver%2Flawson/lists"}