Database

What is Shypyard database?

Every app comes with a simple managed key/value database system you can use in your task. The data are fully independent and private. This allows you to persist state across different task runs so it can do more complicated automations.
For example, lets say you want to automatically update product description when it is out of stock. You may want to store the original description in the database when the inventory reaches 0, and then upon re-stocking, read from the database and re-store the old description.

Usage Example

Using the example from earlier, here's a pseudo code to show how database can be used.
1
const { auths, libs } = require('platform');
2
​
3
module.exports = async (event, options) => {
4
const shopify = libs.shopify.get();
5
const db = libs.shypyard.get().db();
6
7
// get full product detail
8
const product = await shopify.product.get(event.data.id);
9
const key = `old-product-description:${product.id}`;
10
11
if (product.inventory == 0) {
12
// when product is out of stock, change description and
13
await db.set(key, { val: product.description_html });
14
15
await shopify.product.update(
16
product.id,
17
{ description_html: '....some new description' },
18
);
19
} else {
20
// restore old description
21
const {val: oldVal} = await db.get(key);
22
await shopify.product.update(
23
product.id,
24
{ description_html: oldVal },
25
);
26
}
27
};
Copied!

Web UI

You can see the database value by going to Storage > Database section. Here you can do basic filtering on key prefix. Note that every database key also automatically track a createdAt attribute.

See detailed documentation

Please see the Shypyard SDK documention on shypyard database.
Last modified 7mo ago