{"id":22351879,"url":"https://github.com/screwdriver-cd/datastore-base","last_synced_at":"2025-07-30T07:31:55.037Z","repository":{"id":48824056,"uuid":"60306651","full_name":"screwdriver-cd/datastore-base","owner":"screwdriver-cd","description":"Base class defining the interface for datastore implementations","archived":false,"fork":false,"pushed_at":"2024-09-04T18:38:21.000Z","size":58,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-11-09T20:44:35.986Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/screwdriver-datastore-base","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/screwdriver-cd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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-06-03T00:39:03.000Z","updated_at":"2024-09-04T18:36:59.000Z","dependencies_parsed_at":"2024-09-05T20:49:34.166Z","dependency_job_id":null,"html_url":"https://github.com/screwdriver-cd/datastore-base","commit_stats":{"total_commits":42,"total_committers":17,"mean_commits":"2.4705882352941178","dds":0.8095238095238095,"last_synced_commit":"b4e7253a687445400ad347307036886acb4b5f9f"},"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/screwdriver-cd%2Fdatastore-base","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/screwdriver-cd%2Fdatastore-base/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/screwdriver-cd%2Fdatastore-base/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/screwdriver-cd%2Fdatastore-base/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/screwdriver-cd","download_url":"https://codeload.github.com/screwdriver-cd/datastore-base/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228106387,"owners_count":17870438,"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-12-04T12:16:13.298Z","updated_at":"2024-12-04T12:16:14.098Z","avatar_url":"https://github.com/screwdriver-cd.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# datastore base\n[![Version][npm-image]][npm-url] ![Downloads][downloads-image] [![Build Status][status-image]][status-url] [![Open Issues][issues-image]][issues-url] ![License][license-image]\n\n\u003e Base class defining the interface for datastore implementations\n\nThis base class should be used for defining different datastore options for the screwdriver api.\nThe functions exposed contain input validation for to define the contract for datastores so that it\nis agnostic of the actual implementation.\n\n## Usage\n\n```bash\nnpm install screwdriver-datastore-base\n```\n\n## Extending\n```js\nclass MyDatastore extends Datastore {\n    // Implement the interface\n    _get(config) {\n\n        // do something to fetch data...\n\n        if (config.params.id \u003e 0) {\n            return Promise.resolve({ id: config.params.id });\n        }\n\n        return Promise.reject('Some error');\n    }\n}\n\nconst store = new MyDatastore({});\nreturn store.get({ table: 'tablename', params: { id: 1 } })\n    .then((err, data) =\u003e {\n        // do something....\n    });\n```\n\nThe base class exposes a set of functions:\n* `get`\n* `save`\n* `update`\n* `scan`\n* `remove`\n* `query`\n\nAll of those functions provide input validation on the config object being passed in,\nand call an underlying function with the arguments passed in.\n\nTo take advantage of the input validation, override these functions:\n* `_get`\n* `_save`\n* `_update`\n* `_scan`\n* `_remove`\n* `_query`\n\nAdditionally, there is a `setup` function which will be called by Screwdriver to allow the\ndatastore to create or upgrade tables as needed.\n\n## Interface\n\n### get\n\n| Parameter | Type | Description |\n| :-- | :-- | :-- |\n|config | Object | Each of its properties defines your get operation |\n|config.table | String | The datastore table name |\n|config.params| Object | Each of its properties defines the get parameters |\n|config.params.id| String | The ID of the item to fetch from the datastore |\n\n\n#### Expected Outcome\nThe get function is expected to fetch a single record with a specific id.\n\n#### Expected Return\nA promise that resolves to the record if found, null if not found, and rejects if it fails.\n\n###  save\n\n| Parameter | Type | Description |\n| :-- | :-- | :-- |\n|config | Object | Each of its properties defines your get operation |\n|config.table | String | The datastore table name |\n|config.params| Object | The data that will be saved in the datastore |\n\n#### Expected Outcome\nThe save function is expected to save a record to the datastore.\n\n#### Expected Return\nA promise that resolves to the record if saved successfully, or rejects if it fails.\n\n\n###  remove\n\n| Parameter | Type | Description |\n| :-- | :-- | :-- |\n|config | Object | Each of its properties defines your get operation |\n|config.table | String | The datastore table name |\n|config.params| Object | Each of its properties defines the get parameters |\n|config.params.id| String |  The ID of the data to remove |\n\n#### Expected Outcome\nThe remove function is expected to remove a record from the datastore.\n\n#### Expected Return\nA promise that resolves to null if remove successfully, or rejects if it fails.\n\n\n###  update\n\n| Parameter | Type | Description |\n| :-- | :-- | :-- |\n|config | Object | Each of its properties defines your get operation |\n|config.table | String | The datastore table name |\n|config.params| Object | The data to be updated in the datastore |\n|config.params.id| String | The ID that the data is associated with |\n\nUpdate a record in the datastore. Returns `null` if the record does not exist.\n\n#### Expected Outcome\nThe update function is expected to update a record in the datastore.\n\n#### Expected Return\nA promise that resolves to the record if updated successfully, null if the record does not exist, and rejects if fails.\n\n### scan\n\n| Parameter | Type | Description |\n| :-- | :-- | :-- |\n|config | Object | Each of its properties defines your get operation |\n|config.table | String | The datastore table name |\n|config.params| Object | Query to filter on |\n|config.paginate| Object | Each of its properties further defines the characteristics for pagination |\n|config.paginate.count| Integer | Number of items per page |\n|config.paginate.page| Integer | Page number of the set you wish for the datastore to return |\n\n#### Expected Outcome\nThe scan function is expected to fetch multiple records from the datastore.\n\n#### Expected Return\nA promise that resolves to an array of records, or rejects if fails.\n\n#### Example datastores\n- [screwdriver-datastore-imdb](https://github.com/screwdriver-cd/datastore-imdb)\n- [screwdriver-datastore-dynamodb](https://github.com/screwdriver-cd/datastore-dynamodb)\n\n### query\n\n| Parameter | Type | Description |\n| :-- | :-- | :-- |\n|config | Object | Each of its properties defines your operation |\n|config.table | String | The datastore table name |\n|config.queries| Array | Map of datastore type to related query |\n|config.replacements| Object | Each of its properties are parameters that are replaced in the query |\n|config.rawResponse| Boolean | Whether to return raw response or bind to model associated with table |\n\n#### Expected Outcome\nThe query function is expected to run one of the given queries, based on datastore type, and return the response, either as raw data or bound to a model.\n\n#### Expected Return\nA promise that resolves to an array of records, or rejects if fails.\n\n\n## Testing\n\n```bash\nnpm test\n```\n\n## License\n\nCode licensed under the BSD 3-Clause license. See LICENSE file for terms.\n\n[npm-image]: https://img.shields.io/npm/v/screwdriver-datastore-base.svg\n[npm-url]: https://npmjs.org/package/screwdriver-datastore-base\n[downloads-image]: https://img.shields.io/npm/dt/screwdriver-datastore-base.svg\n[license-image]: https://img.shields.io/npm/l/screwdriver-datastore-base.svg\n[issues-image]: https://img.shields.io/github/issues/screwdriver-cd/screwdriver.svg\n[issues-url]: https://github.com/screwdriver-cd/screwdriver/issues\n[status-image]: https://cd.screwdriver.cd/pipelines/14/badge\n[status-url]: https://cd.screwdriver.cd/pipelines/14\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscrewdriver-cd%2Fdatastore-base","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscrewdriver-cd%2Fdatastore-base","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscrewdriver-cd%2Fdatastore-base/lists"}