6.0.1 • Published 2 months ago

screwdriver-datastore-base v6.0.1

Weekly downloads
55
License
BSD-3-Clause
Repository
github
Last release
2 months ago

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.

6.0.1

2 months ago

6.0.0

1 year ago

5.1.0

3 years ago

5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

4 years ago

4.0.0

4 years ago

3.1.0

4 years ago

3.0.8

5 years ago

3.0.7

6 years ago

3.0.6

6 years ago

3.0.5

6 years ago

3.0.4

7 years ago

3.0.3

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.3.0

7 years ago

2.2.1

7 years ago

2.2.0

8 years ago

2.1.3

8 years ago

2.1.2

8 years ago

2.1.1

8 years ago

2.1.0

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago