npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

screwdriver-datastore-base

v7.0.0

Published

Base class defining the interface for datastore implementations

Downloads

285

Readme

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

| Parameter | Type | Description | | :-- | :-- | :-- | |config | Object | Each of its properties defines your get operation | |config.table | String | The datastore table name | |config.params| Object | Each of its properties defines the get parameters | |config.params.id| String | The 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

| Parameter | Type | Description | | :-- | :-- | :-- | |config | Object | Each of its properties defines your get operation | |config.table | String | The datastore table name | |config.params| Object | The 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

| Parameter | Type | Description | | :-- | :-- | :-- | |config | Object | Each of its properties defines your get operation | |config.table | String | The datastore table name | |config.params| Object | Each of its properties defines the get parameters | |config.params.id| String | The 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

| Parameter | Type | Description | | :-- | :-- | :-- | |config | Object | Each of its properties defines your get operation | |config.table | String | The datastore table name | |config.params| Object | The data to be updated in the datastore | |config.params.id| String | The 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

| Parameter | Type | Description | | :-- | :-- | :-- | |config | Object | Each of its properties defines your get operation | |config.table | String | The datastore table name | |config.params| Object | Query to filter on | |config.paginate| Object | Each of its properties further defines the characteristics for pagination | |config.paginate.count| Integer | Number of items per page | |config.paginate.page| Integer | Page 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

| Parameter | Type | Description | | :-- | :-- | :-- | |config | Object | Each of its properties defines your operation | |config.table | String | The datastore table name | |config.queries| Array | Map of datastore type to related query | |config.replacements| Object | Each of its properties are parameters that are replaced in the query | |config.rawResponse| Boolean | Whether 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.