![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
screwdriver-datastore-imdb
Advanced tools
In-memory datastore for use with the Screwdriver API
npm install screwdriver-datastore-imdb
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 classconfig.db
- Optional An object
to initialize the database withconfig.filename
- Optional A filename
to initialize the database with. If both db
and filename
are passed in, the db
value will be ignoredconst Imdb = require('screwdriver-datastore-imdb');
const imdb = new Imdb();
imdb.get('table1', 'key1').then(console.log); // Outputs null
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' }
const imdb3 = new Imdb({
db: {
table1: {
key1: {
foo: 'bar'
}
}
}
});
imdb3.get('table1', 'key1').then(console.log); // Outputs { foo: 'bar' }
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 operationconfig.table
- A string
. The datastore table nameconfig.params
- An object. Each of its properties defines the get parametersconfig.params.id
- A string
. The ID of the item to fetch from the datastoreExample
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 a record in the datastore. Returns saved data.
Arguments
config
- An object
. Each of its properties defines your save operationconfig.table
- A string
. The datastore table nameconfig.params
- An object. Each of its properties defines the save parametersconfig.params.id
- A string
. The ID to associate the data withconfig.params.data
- An object. This is what will be saved in the datastoreconst 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 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 operationconfig.table
- A string
. The datastore table nameconfig.params
- An object. Each of its properties defines the save parametersconfig.params.id
- A string
. The ID to associate the data withconfig.params.data
- An object. This is what will be saved in the datastoreconst 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
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 operationconfig.table
- A string
. The datastore table nameconfig.params
- An object. Each of its properties defines the query parametersconfig.paginate
- An object. Each of its properties further defines the characteristics for paginationconfig.paginate.count
- An integer
. This is the number of items per pageconfig.paginate.page
- An integer
. This is the page number of the set you wish for the datastore to returnExample
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"]
npm test
Code licensed under the BSD 3-Clause license. See LICENSE file for terms.
FAQs
In-memory datastore for use with the Screwdriver API
The npm package screwdriver-datastore-imdb receives a total of 10 weekly downloads. As such, screwdriver-datastore-imdb popularity was classified as not popular.
We found that screwdriver-datastore-imdb demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.