{"id":20688560,"url":"https://github.com/superraytin/gitlab-db","last_synced_at":"2025-07-04T12:02:16.084Z","repository":{"id":45906657,"uuid":"116833346","full_name":"superRaytin/gitlab-db","owner":"superRaytin","description":"A lightweight Gitlab based JSON database with Mongo-style API.","archived":false,"fork":false,"pushed_at":"2021-11-29T03:13:57.000Z","size":89,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-19T11:51:32.749Z","etag":null,"topics":["db","gitlab","gitlab-api","javascript","nodejs"],"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/superRaytin.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}},"created_at":"2018-01-09T15:23:59.000Z","updated_at":"2023-03-16T10:26:14.000Z","dependencies_parsed_at":"2022-08-27T21:02:26.961Z","dependency_job_id":null,"html_url":"https://github.com/superRaytin/gitlab-db","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superRaytin%2Fgitlab-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superRaytin%2Fgitlab-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superRaytin%2Fgitlab-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superRaytin%2Fgitlab-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/superRaytin","download_url":"https://codeload.github.com/superRaytin/gitlab-db/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250269953,"owners_count":21402970,"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":["db","gitlab","gitlab-api","javascript","nodejs"],"created_at":"2024-11-16T23:06:06.824Z","updated_at":"2025-04-22T15:42:15.995Z","avatar_url":"https://github.com/superRaytin.png","language":"JavaScript","readme":"# gitlab-db\nA lightweight Gitlab based JSON database with Mongo-style API. Backed by [gitbeaker](https://github.com/jdalrymple/gitbeaker) and [mingo](https://github.com/kofrasa/mingo).\n\n[![NPM version][npm-image]][npm-url]\n[![Downloads][downloads-image]][npm-url]\n\n[npm-url]: https://npmjs.org/package/gitlab-db\n[downloads-image]: http://img.shields.io/npm/dm/gitlab-db.svg\n[npm-image]: http://img.shields.io/npm/v/gitlab-db.svg\n\n## Install\n\n```\nnpm i gitlab-db\n```\n\n## Quick Start\n\n```js\nimport GitlabDB from 'gitlab-db'\n\n// Instantiate a database\nconst db = new GitlabDB('apple', {\n  url: 'http://gitlab.example.com',\n  token: 'your_access_token',\n  repo: 'group/repo',\n})\n\n// Create a collection\ndb.createCollection('product')\n\n// CRUD\ndb.collection('product').save({ name: 'iphone', v: '8', price: 699 })\ndb.collection('product').find({ name: 'iphone' })\ndb.collection('product').update({ name: 'iphone', v: '8' }, { price: 599 })\ndb.collection('product').remove({ name: 'iphone', v: '7' })\n```\n\nRepository structure will be:\n\n```\n└── \u003crepository root\u003e\n    ├── apple\n    │   └── product.json\n```\n\n## API\n\nNote: As all APIs returns a promise. I highly recommend the `async/await` statement like the following:\n\n```js\nconst result = await db.collection('product').save({ name: 'iphone', v: '8', price: 699 })\n```\n\n### constructor(dbName, options[, customGitlabAPI])\n\nInstantiate a database.\n\n- **dbName:** `String` Name of the database you want to create.\n- **options:** `Object`\n  - **url:** `String` Specify gitlab url, eg: `http://gitlab.example.com`.\n  - **token:** `String` Specify your personal access token.\n  - **repo:** `String` Specify repository name and group belongs to, format: `group/repo`.\n  - **branch:** `String` Optional, specify branch, default: `main`.\n- **customGitlabAPI:** `Constructor` Specify your custom GitlabAPI like `@gitbeaker/browser`.\n\n### db.createCollection(collectionName [, documents])\n\nCreate a collection.\n\n- **collectionName:** `String` Name of the collection you want to create.\n- **documents:** `Array` Optional. Specifies default data of the collection about to be created.\n\n### db.collection(collectionName [, options])\n\nConnect to a collection.\n\n- **collectionName:** `String` Name of the collection you want to connect.\n- **options:** `Object` Optional settings.\n  - **key:** `String` Specify a key of the collection.\n\n### db.collection(collectionName).save(document)\n\nInserts a new document(or multiple documents). This method will returns the inserted document(s).\n\n- **document:** `Object` | `Array` A document or multiple documents to save to the collection.\n\nReturns like:\n\n\u003e Insert single document:\n\n```js\n{ added: 1, document: {...} }\n```\n\n\u003e Insert multiple documents:\n\n```js\n{ added: 2, documents: [{...}, {...}] }\n```\n\nNote: it will return `{ added: 0 }` if a key is specified and the document that the key points to already exists.\n\n### db.collection(collectionName).find([query])\n\nSelects documents in a collection.\n\n- **query:** `Object` Optional. Specifies selection filter using query operators. To return all documents in a collection, omit this parameter or pass an empty document ({}).\n\nReturns like:\n\n```js\n[{ _id: 1, ... }]\n```\n\n### db.collection(collectionName).update(query, update)\n\nModifies an existing document or documents in a collection.\n\n- **query:** `Object` The selection criteria for the update. The same query selectors as in the find() method are available.\n- **update:** `Object` The modifications to apply.\n\nReturns like:\n\n```js\n{ updated: 2 }\n```\n\nAnother usage, execute multiple updates at once to reduce gitlab requests:\n\n```js\ndb.collection(collectionName).update([\n    { query: { id: 1 }, update: { v: 1 } },\n    { query: { id: 2 }, update: { v: 2 } },\n])\n```\n\n### db.collection(collectionName).remove(query)\n\nRemoves documents from a collection.\n\n- **query:** `Object` Specifies deletion criteria using query operators.\n\nReturns like:\n\n```js\n{ removed: 1 }\n```\n\n### db.isCollectionExists(collectionName)\n\nCheck if a collection exists.\n\n- **collectionName:** `String` Name of the collection you want to check.\n\nReturns like:\n\n```js\ntrue\n```\n\n## Use in Browser\n\n```js\nimport { Gitlab } from '@gitbeaker/browser'; \nimport GitlabDB from 'gitlab-db'\n\n// Instantiate a database\nconst db = new GitlabDB('apple', {\n  url: 'http://gitlab.example.com',\n  token: 'your_access_token',\n  repo: 'group/repo',\n}, Gitlab)\n\n// ETC...\n```\n\n## Next\n\n- [ ] model check\n- [ ] collection deletion\n\n## Test\n\nConfig your environment variables `GITLAB_URL` `ACCESS_TOKEN` `REPO`, and run tests with:\n\n```\nGITLAB_URL={your_gitlab_url} ACCESS_TOKEN={your_access_token} REPO={yourGroup/yourRepo} npm run test\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperraytin%2Fgitlab-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuperraytin%2Fgitlab-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperraytin%2Fgitlab-db/lists"}