@blinkdotnew/sdk 0.14.10 → 0.14.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,8 +35,8 @@ const user = await blink.auth.me()
|
|
|
35
35
|
|
|
36
36
|
// Database operations (zero config)
|
|
37
37
|
const todos = await blink.db.todos.list({
|
|
38
|
-
where: {
|
|
39
|
-
orderBy: {
|
|
38
|
+
where: { userId: user.id },
|
|
39
|
+
orderBy: { createdAt: 'desc' },
|
|
40
40
|
limit: 20
|
|
41
41
|
})
|
|
42
42
|
|
|
@@ -205,6 +205,11 @@ The SDK now automatically converts between JavaScript camelCase and SQL snake_ca
|
|
|
205
205
|
- **Stored as snake_case**: `user_id`, `created_at`, `is_completed`
|
|
206
206
|
- **No manual conversion needed!**
|
|
207
207
|
|
|
208
|
+
**⚠️ Important: Always Use camelCase in Your Code**
|
|
209
|
+
- ✅ **Correct**: `{ userId: user.id, createdAt: new Date() }`
|
|
210
|
+
- ❌ **Wrong**: `{ user_id: user.id, created_at: new Date() }`
|
|
211
|
+
|
|
212
|
+
|
|
208
213
|
```typescript
|
|
209
214
|
// Create (ID auto-generated if not provided)
|
|
210
215
|
const todo = await blink.db.todos.create({
|
|
@@ -230,24 +235,23 @@ const todos = await blink.db.todos.list({
|
|
|
230
235
|
|
|
231
236
|
// Note: Boolean fields are returned as "0"/"1" strings from SQLite
|
|
232
237
|
// Check boolean values using Number(value) > 0
|
|
233
|
-
const completedTodos = todos.filter(todo => Number(todo.
|
|
234
|
-
const incompleteTodos = todos.filter(todo => Number(todo.
|
|
238
|
+
const completedTodos = todos.filter(todo => Number(todo.isCompleted) > 0)
|
|
239
|
+
const incompleteTodos = todos.filter(todo => Number(todo.isCompleted) === 0)
|
|
235
240
|
|
|
236
241
|
// Update
|
|
237
|
-
await blink.db.todos.update(todo.id, {
|
|
242
|
+
await blink.db.todos.update(todo.id, { isCompleted: true })
|
|
238
243
|
|
|
239
244
|
// Delete
|
|
240
245
|
await blink.db.todos.delete(todo.id)
|
|
241
246
|
|
|
242
247
|
// Bulk operations (IDs auto-generated if not provided)
|
|
243
248
|
await blink.db.todos.createMany([
|
|
244
|
-
{ title: 'Task 1',
|
|
245
|
-
{ id: 'custom_id', title: 'Task 2',
|
|
249
|
+
{ title: 'Task 1', userId: user.id }, // ID will be auto-generated
|
|
250
|
+
{ id: 'custom_id', title: 'Task 2', userId: user.id } // Custom ID provided
|
|
246
251
|
])
|
|
247
252
|
await blink.db.todos.upsertMany([...])
|
|
248
253
|
|
|
249
|
-
|
|
250
|
-
const result = await blink.db.sql('SELECT * FROM todos WHERE user_id = ?', [user.id])
|
|
254
|
+
|
|
251
255
|
```
|
|
252
256
|
|
|
253
257
|
### AI Operations
|
|
@@ -1209,9 +1213,9 @@ The SDK is written in TypeScript and provides full type safety:
|
|
|
1209
1213
|
interface Todo {
|
|
1210
1214
|
id: string
|
|
1211
1215
|
title: string
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1216
|
+
isCompleted: boolean // Will be returned as "0" or "1" string from SQLite
|
|
1217
|
+
userId: string // Automatically converted from snake_case user_id
|
|
1218
|
+
createdAt: string // Automatically converted from snake_case created_at
|
|
1215
1219
|
}
|
|
1216
1220
|
|
|
1217
1221
|
// Note: Boolean fields are returned as "0"/"1" strings from SQLite
|
|
@@ -1219,12 +1223,12 @@ interface Todo {
|
|
|
1219
1223
|
const todos = await blink.db.todos.list<Todo>()
|
|
1220
1224
|
|
|
1221
1225
|
// Check boolean values properly
|
|
1222
|
-
const completedTodos = todos.filter(todo => Number(todo.
|
|
1223
|
-
const incompleteTodos = todos.filter(todo => Number(todo.
|
|
1226
|
+
const completedTodos = todos.filter(todo => Number(todo.isCompleted) > 0)
|
|
1227
|
+
const incompleteTodos = todos.filter(todo => Number(todo.isCompleted) === 0)
|
|
1224
1228
|
|
|
1225
1229
|
// When filtering by boolean values in queries, use "0"/"1" strings
|
|
1226
1230
|
const onlyCompleted = await blink.db.todos.list<Todo>({
|
|
1227
|
-
where: {
|
|
1231
|
+
where: { isCompleted: "1" } // Use string "1" for true, "0" for false
|
|
1228
1232
|
})
|
|
1229
1233
|
// todos is fully typed as Todo[]
|
|
1230
1234
|
```
|
package/package.json
CHANGED