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-imdb

v1.0.18

Published

In-memory datastore for use with the Screwdriver API

Downloads

19

Readme

Screwdriver In-Memory Datastore

Version Downloads Build Status Open Issues Dependency Status License

In-memory datastore for use with the Screwdriver API

Usage

npm install screwdriver-datastore-imdb

Initialization

The IMDB is an extension of the screwdriver-datastore-base class and implements all of the functions exposed.

The IMDB takes in an optional config parameter as a JSON object that will be used to initialize the in-memory database.

Arguments

  • config - Optional An object passed to the initialization of the class
  • config.db - Optional An object to initialize the database with
  • config.filename - Optional A filename to initialize the database with. If both db and filename are passed in, the db value will be ignored
const Imdb = require('screwdriver-datastore-imdb');

Without a database (will initialize with {} as default)

const imdb = new Imdb();

imdb.get('table1', 'key1').then(console.log);  // Outputs null

With a filename

Example file some/path/to/config.json:

{
    table1: {
        key1: {
            foo: 'bar'
        }
    }
}
const imdb2 = new Imdb({
  filename: 'some/path/to/config.json'
});

imdb2.get('table1', 'key1').then(console.log);    // Outputs { foo: 'bar' }

With a database

const imdb3 = new Imdb({
  db: {
      table1: {
          key1: {
              foo: 'bar'
          }
      }
  }
});

imdb3.get('table1', 'key1').then(console.log);    // Outputs { foo: 'bar' }

get

Obtain a single record given an id. Returns null if the record does not exist.

Arguments

  • config - An object. Each of its properties defines your get operation
  • config.table - A string. The datastore table name
  • config.params - An object. Each of its properties defines the get parameters
  • config.params.id - A string. The ID of the item to fetch from the datastore

Example

const Imdb = require('screwdriver-datastore-imdb');
const imdb = new Imdb();

// successful get operation
imdb.get({
    table: 'fruits',
    params: {
        id: 'apple'
    }
}).then(console.log);  // { color: 'red', type: 'fruit' }

// get operation on a non-existing entry
imdb.get({
    table: 'fruits',
    params: {
        id: 'celery'
    }
}).then(console.log);  // null

save

Save a record in the datastore. Returns saved data.

Arguments

  • config - An object. Each of its properties defines your save operation
  • config.table - A string. The datastore table name
  • config.params - An object. Each of its properties defines the save parameters
  • config.params.id - A string. The ID to associate the data with
  • config.params.data - An object. This is what will be saved in the datastore
const Imdb = require('screwdriver-datastore-imdb');
const imdb = new Imdb({
    db: {
        favorites: {
            fruit: {
                name: 'cherry'
            }
        }
    }
});


// overwrite pre-existing entry
imdb.save({
    table: 'favorites',
    params: {
        id: 'fruit',
        data: {
            name: 'pear'
        }
    }
}).then(console.log);  // { id: 'fruit', name: 'cherry' }


// save new entry
imdb.save({
    table: 'favorites',
    params: {
        id: 'meal',
        data: {
            name: 'mac & cheese'
        }
    }
}).then(console.log);  // { id: 'meal', name: 'mac & cheese' }

update

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

Arguments

  • config - An object. Each of its properties defines your save operation
  • config.table - A string. The datastore table name
  • config.params - An object. Each of its properties defines the save parameters
  • config.params.id - A string. The ID to associate the data with
  • config.params.data - An object. This is what will be saved in the datastore
const Imdb = require('screwdriver-datastore-imdb');
const imdb = new Imdb({
    db: {
        meals: {
            lunch: {
                main: 'sandwich',
                side: 'chips'
            }
        }
    }
});


// update entry
imdb.update({
    table: 'meals',
    params: {
        id: 'lunch',
        data: {
            drink: 'ice tea'
        }
    }
}).then(console.log);  // { id: 'lunch', main: 'sandwich', side: 'chips', drink: 'ice tea' }


// update a non-existing entry
imdb.save({
    table: 'meals',
    params: {
        id: 'breakfast',
        data: {
            main: 'milk & cereal'
        }
    }
}).then(console.log);  // null

scan

Fetch multiple records from the datastore. Returns [] if the table is empty. Rejects with an error if table does not exist.

Arguments

  • config - An object. Each of its properties defines your scan operation
  • config.table - A string. The datastore table name
  • config.params - An object. Each of its properties defines the query parameters
  • config.paginate - An object. Each of its properties further defines the characteristics for pagination
  • config.paginate.count - An integer. This is the number of items per page
  • config.paginate.page - An integer. This is the page number of the set you wish for the datastore to return

Example

const Imdb = require('screwdriver-datastore-imdb');
const imdb = new Imdb();

// valid scan
imdb.scan({
    table: 'primarycolors',
    params: {},
    paginate: {
        page: 1,
        count: 2
    }
}).then(console.log);  // [{ id: 0, name: 'blue' }, { id: 1, name: 'green'}]

// best effort based on given criteria
imdb.scan({
    table: 'primarycolors',
    params: {},
    paginate: {
        page: 2,
        count: 2
    }
}).then(console.log);  // [{ id: 2, name: 'red' }]

// no results found
imdb.scan({
    table: 'primarycolors',
    params: {},
    paginate: {
        page: 3,
        count: 2
    }
}).then(console.log); // []

// scan operation on a non-existing entry
datastore.scan({
    table: 'unicorns',
    params: {},
    paginate: {
        page: 2,
        count: 2
    }
}).catch(console.error);  // [Error: Invalid table name "unicorns"]

Testing

npm test

License

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