Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

screwdriver-datastore-base

Package Overview
Dependencies
Maintainers
0
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

screwdriver-datastore-base

Base class defining the interface for datastore implementations

  • 7.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

datastore base

Version Downloads Build Status Open Issues License

Base class defining the interface for datastore implementations

This base class should be used for defining different datastore options for the screwdriver api. The functions exposed contain input validation for to define the contract for datastores so that it is agnostic of the actual implementation.

Usage

npm install screwdriver-datastore-base

Extending

class MyDatastore extends Datastore {
    // Implement the interface
    _get(config) {

        // do something to fetch data...

        if (config.params.id > 0) {
            return Promise.resolve({ id: config.params.id });
        }

        return Promise.reject('Some error');
    }
}

const store = new MyDatastore({});
return store.get({ table: 'tablename', params: { id: 1 } })
    .then((err, data) => {
        // do something....
    });

The base class exposes a set of functions:

  • get
  • save
  • update
  • scan
  • remove
  • query

All of those functions provide input validation on the config object being passed in, and call an underlying function with the arguments passed in.

To take advantage of the input validation, override these functions:

  • _get
  • _save
  • _update
  • _scan
  • _remove
  • _query

Additionally, there is a setup function which will be called by Screwdriver to allow the datastore to create or upgrade tables as needed.

Interface

get

ParameterTypeDescription
configObjectEach of its properties defines your get operation
config.tableStringThe datastore table name
config.paramsObjectEach of its properties defines the get parameters
config.params.idStringThe ID of the item to fetch from the datastore
Expected Outcome

The get function is expected to fetch a single record with a specific id.

Expected Return

A promise that resolves to the record if found, null if not found, and rejects if it fails.

save

ParameterTypeDescription
configObjectEach of its properties defines your get operation
config.tableStringThe datastore table name
config.paramsObjectThe data that will be saved in the datastore
Expected Outcome

The save function is expected to save a record to the datastore.

Expected Return

A promise that resolves to the record if saved successfully, or rejects if it fails.

remove

ParameterTypeDescription
configObjectEach of its properties defines your get operation
config.tableStringThe datastore table name
config.paramsObjectEach of its properties defines the get parameters
config.params.idStringThe ID of the data to remove
Expected Outcome

The remove function is expected to remove a record from the datastore.

Expected Return

A promise that resolves to null if remove successfully, or rejects if it fails.

update

ParameterTypeDescription
configObjectEach of its properties defines your get operation
config.tableStringThe datastore table name
config.paramsObjectThe data to be updated in the datastore
config.params.idStringThe ID that the data is associated with

Update a record in the datastore. Returns null if the record does not exist.

Expected Outcome

The update function is expected to update a record in the datastore.

Expected Return

A promise that resolves to the record if updated successfully, null if the record does not exist, and rejects if fails.

scan

ParameterTypeDescription
configObjectEach of its properties defines your get operation
config.tableStringThe datastore table name
config.paramsObjectQuery to filter on
config.paginateObjectEach of its properties further defines the characteristics for pagination
config.paginate.countIntegerNumber of items per page
config.paginate.pageIntegerPage number of the set you wish for the datastore to return
Expected Outcome

The scan function is expected to fetch multiple records from the datastore.

Expected Return

A promise that resolves to an array of records, or rejects if fails.

Example datastores

query

ParameterTypeDescription
configObjectEach of its properties defines your operation
config.tableStringThe datastore table name
config.queriesArrayMap of datastore type to related query
config.replacementsObjectEach of its properties are parameters that are replaced in the query
config.rawResponseBooleanWhether to return raw response or bind to model associated with table
Expected Outcome

The 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.

Expected Return

A promise that resolves to an array of records, or rejects if fails.

Testing

npm test

License

Code licensed under the BSD 3-Clause license. See LICENSE file for terms.

Keywords

FAQs

Package last updated on 04 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc