Skip to content

Commit 4344720

Browse files
change data to dataStore
1 parent db02c58 commit 4344720

File tree

2 files changed

+47
-47
lines changed

2 files changed

+47
-47
lines changed

docs-v2/pages/workflows/building-workflows/code/nodejs/using-data-stores.mdx

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ In Node.js (Javascript) code steps, you can also store and retrieve data within
66

77
Add data stores to steps as props. By adding the store as a prop, it's available under `this`.
88

9-
For example, you can define a data store as a data prop, and reference it at `this.data`:
9+
For example, you can define a data store as a dataStore prop, and reference it at `this.dataStore`:
1010

1111
```javascript
1212
export default defineComponent({
1313
props: {
14-
// Define that the "data" variable in our component is a data store
15-
data: { type: "data_store" },
14+
// Define that the "dataStore" variable in our component is a data store
15+
dataStore: { type: "data_store" },
1616
},
1717
async run({ steps, $ }) {
18-
// Now we can access the data store at "this.data"
19-
await this.data.get("email");
18+
// Now we can access the data store at "this.dataStore"
19+
await this.dataStore.get("email");
2020
},
2121
});
2222
```
2323

2424
<Callout type="info">
25-
**`props` injects variables into `this`**. See how we declared the `data` prop in the `props` object, and then accessed it at `this.data` in the `run` method.
25+
**`props` injects variables into `this`**. See how we declared the `dataStore` prop in the `props` object, and then accessed it at `this.dataStore` in the `run` method.
2626
</Callout>
2727

2828
<Callout type="warning">
@@ -37,16 +37,16 @@ Once you've defined a data store prop for your component, then you'll be able to
3737

3838
## Saving data
3939

40-
Data Stores are key-value stores. Save data within a Data Store using the `this.data.set` method. The first argument is the _key_ where the data should be held, and the second argument is the _value_ assigned to that key.
40+
Data Stores are key-value stores. Save data within a Data Store using the `this.dataStore.set` method. The first argument is the _key_ where the data should be held, and the second argument is the _value_ assigned to that key.
4141

4242
```javascript
4343
export default defineComponent({
4444
props: {
45-
data: { type: "data_store" },
45+
dataStore: { type: "data_store" },
4646
},
4747
async run({ steps, $ }) {
4848
// Store a timestamp each time this step is executed in the workflow
49-
await this.data.set("lastRanAt", new Date());
49+
await this.dataStore.set("lastRanAt", new Date());
5050
},
5151
});
5252
```
@@ -58,14 +58,14 @@ You can set an expiration time for a record by passing a TTL (Time-To-Live) opti
5858
```javascript
5959
export default defineComponent({
6060
props: {
61-
data: { type: "data_store" },
61+
dataStore: { type: "data_store" },
6262
},
6363
async run({ steps, $ }) {
6464
// Store a temporary value that will expire after 1 hour (3600 seconds)
65-
await this.data.set("temporaryToken", "abc123", { ttl: 3600 });
66-
65+
await this.dataStore.set("temporaryToken", "abc123", { ttl: 3600 });
66+
6767
// Store a value that will expire after 1 day
68-
await this.data.set("dailyMetric", 42, { ttl: 86400 });
68+
await this.dataStore.set("dailyMetric", 42, { ttl: 86400 });
6969
},
7070
});
7171
```
@@ -79,14 +79,14 @@ You can update the TTL for an existing record using the `setTtl` method:
7979
```javascript
8080
export default defineComponent({
8181
props: {
82-
data: { type: "data_store" },
82+
dataStore: { type: "data_store" },
8383
},
8484
async run({ steps, $ }) {
8585
// Update an existing record to expire after 30 minutes
86-
await this.data.setTtl("temporaryToken", 1800);
87-
86+
await this.dataStore.setTtl("temporaryToken", 1800);
87+
8888
// Remove expiration from a record
89-
await this.data.setTtl("temporaryToken", null);
89+
await this.dataStore.setTtl("temporaryToken", null);
9090
},
9191
});
9292
```
@@ -100,11 +100,11 @@ Fetch all the keys in a given Data Store using the `keys` method:
100100
```javascript
101101
export default defineComponent({
102102
props: {
103-
data: { type: "data_store" },
103+
dataStore: { type: "data_store" },
104104
},
105105
async run({ steps, $ }) {
106106
// Return a list of all the keys in a given Data Store
107-
return await this.data.keys();
107+
return await this.dataStore.keys();
108108
},
109109
});
110110
```
@@ -116,11 +116,11 @@ If you need to check whether a specific `key` exists in a Data Store, you can pa
116116
```javascript
117117
export default defineComponent({
118118
props: {
119-
data: { type: "data_store" },
119+
dataStore: { type: "data_store" },
120120
},
121121
async run({ steps, $ }) {
122122
// Check if a specific key exists in your Data Store
123-
return await this.data.has("lastRanAt");
123+
return await this.dataStore.has("lastRanAt");
124124
},
125125
});
126126
```
@@ -132,11 +132,11 @@ You can retrieve data with the Data Store using the `get` method. Pass the _key_
132132
```javascript
133133
export default defineComponent({
134134
props: {
135-
data: { type: "data_store" },
135+
dataStore: { type: "data_store" },
136136
},
137137
async run({ steps, $ }) {
138138
// Check if the lastRanAt key exists
139-
const lastRanAt = await this.data.get("lastRanAt");
139+
const lastRanAt = await this.dataStore.get("lastRanAt");
140140
},
141141
});
142142
```
@@ -148,11 +148,11 @@ Use an async iterator to efficiently retrieve all records or keys in your data s
148148
```javascript
149149
export default defineComponent({
150150
props: {
151-
data: { type: "data_store" },
151+
dataStore: { type: "data_store" },
152152
},
153153
async run({ steps, $ }) {
154154
const records = {};
155-
for await (const [k,v] of this.data) {
155+
for await (const [k,v] of this.dataStore) {
156156
records[k] = v;
157157
}
158158
return records;
@@ -167,14 +167,14 @@ To delete or update the _value_ of an individual record, use the `set` method fo
167167
```javascript
168168
export default defineComponent({
169169
props: {
170-
data: { type: "data_store" },
170+
dataStore: { type: "data_store" },
171171
},
172172
async run({ steps, $ }) {
173173
// Update the value associated with the key, myKey
174-
await this.data.set("myKey", "newValue");
174+
await this.dataStore.set("myKey", "newValue");
175175

176176
// Remove the value but retain the key
177-
await this.data.set("myKey", "");
177+
await this.dataStore.set("myKey", "");
178178
},
179179
});
180180
```
@@ -186,11 +186,11 @@ To delete individual records in a Data Store, use the `delete` method for a spec
186186
```javascript
187187
export default defineComponent({
188188
props: {
189-
data: { type: "data_store" },
189+
dataStore: { type: "data_store" },
190190
},
191191
async run({ steps, $ }) {
192192
// Delete the lastRanAt record
193-
const lastRanAt = await this.data.delete("lastRanAt");
193+
const lastRanAt = await this.dataStore.delete("lastRanAt");
194194
},
195195
});
196196
```
@@ -202,11 +202,11 @@ If you need to delete all records in a given Data Store, you can use the `clear`
202202
```javascript
203203
export default defineComponent({
204204
props: {
205-
data: { type: "data_store" },
205+
dataStore: { type: "data_store" },
206206
},
207207
async run({ steps, $ }) {
208208
// Delete all records from a specific Data Store
209-
return await this.data.clear();
209+
return await this.dataStore.clear();
210210
},
211211
});
212212
```
@@ -243,16 +243,16 @@ You can use a data store as a counter. For example, this code counts the number
243243
```javascript
244244
export default defineComponent({
245245
props: {
246-
data: { type: "data_store" },
246+
dataStore: { type: "data_store" },
247247
},
248248
async run({ steps, $ }) {
249249
// By default, all database entries are undefined.
250250
// It's wise to set a default value so our code as an initial value to work with
251-
const counter = (await this.data.get("counter")) ?? 0;
251+
const counter = (await this.dataStore.get("counter")) ?? 0;
252252

253253
// On the first run "counter" will be 0 and we'll increment it to 1
254254
// The next run will increment the counter to 2, and so forth
255-
await this.data.set("counter", counter + 1);
255+
await this.dataStore.set("counter", counter + 1);
256256
},
257257
});
258258
```
@@ -266,20 +266,20 @@ For example, this workflow's trigger contains an email address from a potential
266266
```javascript
267267
export default defineComponent({
268268
props: {
269-
data: { type: "data_store" },
269+
dataStore: { type: "data_store" },
270270
},
271271
async run({ steps, $ }) {
272272
const email = steps.trigger.event.body.new_customer_email;
273273
// Retrieve the past recorded emails from other runs
274-
const emails = (await this.data.get("emails")) ?? [];
274+
const emails = (await this.dataStore.get("emails")) ?? [];
275275

276276
// If the current email being passed from our webhook is already in our list, exit early
277277
if (emails.includes(email)) {
278278
return $.flow.exit("Already welcomed this user");
279279
}
280280

281281
// Add the current email to the list of past emails so we can detect it in the future runs
282-
await this.data.set("emails", [...emails, email]);
282+
await this.dataStore.set("emails", [...emails, email]);
283283
},
284284
});
285285
```
@@ -291,28 +291,28 @@ TTL functionality is particularly useful for implementing temporary caching and
291291
```javascript
292292
export default defineComponent({
293293
props: {
294-
data: { type: "data_store" },
294+
dataStore: { type: "data_store" },
295295
},
296296
async run({ steps, $ }) {
297297
const userId = steps.trigger.event.userId;
298298
const rateKey = `ratelimit:${userId}`;
299-
299+
300300
// Try to get current rate limit counter
301-
let requests = await this.data.get(rateKey);
302-
301+
let requests = await this.dataStore.get(rateKey);
302+
303303
if (requests === undefined) {
304304
// First request from this user in the time window
305-
await this.data.set(rateKey, 1, { ttl: 3600 }); // Expire after 1 hour
305+
await this.dataStore.set(rateKey, 1, { ttl: 3600 }); // Expire after 1 hour
306306
return { allowed: true, remaining: 4 };
307307
}
308-
308+
309309
if (requests >= 5) {
310310
// Rate limit exceeded
311311
return { allowed: false, error: "Rate limit exceeded", retryAfter: "1 hour" };
312312
}
313-
313+
314314
// Increment the counter
315-
await this.data.set(rateKey, requests + 1);
315+
await this.dataStore.set(rateKey, requests + 1);
316316
return { allowed: true, remaining: 4 - requests };
317317
},
318318
});

docs-v2/pages/workflows/building-workflows/code/python/using-data-stores.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Callout from '@/components/Callout'
22

33
# Using Data Stores
44

5-
You can store and retrieve data from [Data stores](/workflows/data-management/data-stores/) in Python without connecting to a 3rd party database.
5+
You can store and retrieve data from [Data Stores](/workflows/data-management/data-stores/) in Python without connecting to a 3rd party database.
66

77
Add a data store as a input to a Python step, then access it in your Python `handler` with `pd.inputs["data_store"]`.
88

0 commit comments

Comments
 (0)