@data-loom/js v0.0.3-alpha.1
Usage
Install
npm install @data-loom/js
Initializing
import { createClient } from '@data-loom/js'
// Create a single dataloom client for interacting with your database
const dataloom = createClient('https://xyzcompany.feishu.cn/suda/api/v1/workspaces/workspace_abc', 'public-anon-key')
Fetch data
Perform a SELECT query on the table or view.
const { data, error } = await dataloom
.from('characters')
.select()
参数
参数名称 | 必需 | 类型 | 描述 |
---|---|---|---|
columns | Optional | Query | The columns to retrieve, separated by commas. Columns can be renamed when returned with customName:columnName |
options | Required | object | Named parameters |
options
对象
参数名称 | 必需 | 类型 | 描述 |
---|---|---|---|
count | Optional | exact planned estimated | Count algorithm to use to count rows in the table or view. |
head | Optional | boolean | When set to true , data will not be returned. Useful if you only need the count. |
Insert data
Perform an INSERT into the table or view.
const { error } = await dataloom
.from('countries')
.insert({ id: 1, name: 'Mordor' })
参数
参数名称 | 必需 | 类型 | 描述 |
---|---|---|---|
values | Required | Row Array<Row> | The values to insert. Pass an object to insert a single row or an array to insert multiple rows. |
options | Optional | object | Named parameters |
options
对象
参数名称 | 必需 | 类型 | 描述 |
---|---|---|---|
count | Optional | exact planned estimated | Count algorithm to use to count inserted rows. |
defaultToNull | Optional | boolean | Make missing fields default to null . Otherwise, use the default value for the column. Only applies for bulk inserts. |
Update data
Perform an UPDATE on the table or view.
const { error } = await dataloom
.from('instruments')
.update({ name: 'piano' })
.eq('id', 1)
参数
参数名称 | 必需 | 类型 | 描述 |
---|---|---|---|
values | Required | Row | The values to update with |
options | Required | object | Named parameters |
options
对象
参数名称 | 必需 | 类型 | 描述 |
---|---|---|---|
count | Optional | exact planned estimated | Count algorithm to use to count updated rows. |
Delete data
Perform a DELETE on the table or view.
const response = await dataloom
.from('countries')
.delete()
.eq('id', 1)
参数
参数名称 | 必需 | 类型 | 描述 |
---|---|---|---|
options | Required | object | Named parameters |
options
对象
参数名称 | 必需 | 类型 | 描述 |
---|---|---|---|
count | Optional | exact planned estimated | Count algorithm to use to count updated rows. |
Using filters
Filters allow you to only return rows that match certain conditions.
Filters can be used on select(), update(), upsert(), and delete() queries.
- Column is equal to a value
const { data, error } = await dataloom
.from('characters')
.select()
.eq('name', 'Leia')
- Column is not equal to a value
const { data, error } = await dataloom
.from('characters')
.select()
.neq('name', 'Leia')
- Column is greater than a value
const { data, error } = await dataloom
.from('characters')
.select()
.gt('id', 2)
- Column is greater than or equal to a value
const { data, error } = await dataloom
.from('characters')
.select()
.gte('id', 2)
- Column is less than a value
const { data, error } = await dataloom
.from('characters')
.select()
.lt('id', 2)
- Column is less than or equal to a value
const { data, error } = await dataloom
.from('characters')
.select()
.lte('id', 2)
- Column matches a pattern
const { data, error } = await dataloom
.from('characters')
.select()
.like('name', '%Lu%')
- Column matches a case-insensitive pattern
const { data, error } = await dataloom
.from('characters')
.select()
.ilike('name', '%lu%')
- Column is a value
const { data, error } = await dataloom
.from('countries')
.select()
.is('name', null)
- Column is in an array
const { data, error } = await dataloom
.from('characters')
.select()
.in('name', ['Leia', 'Han'])
- Match an associated value
const { data, error } = await dataloom
.from('characters')
.select('name')
.match({ id: 2, name: 'Leia' })
- Don't match the filter
const { data, error } = await dataloom
.from('countries')
.select()
.not('name', 'is', null)
- Don't match the filter
const { data, error } = await dataloom
.from('characters')
.select('name')
.or('id.eq.2,name.eq.Han')
- Match the filter
const { data, error } = await dataloom
.from('characters')
.select()
.filter('name', 'in', '("Han","Yoda")')
Using modifiers
Filters work on the row level—they allow you to return rows that only match certain conditions without changing the shape of the rows. Modifiers are everything that don't fit that definition—allowing you to change the format of the response (e.g., returning a CSV string).
Modifiers must be specified after filters. Some modifiers only apply for queries that return rows
- Order the results
const { data, error } = await dataloom
.from('characters')
.select('id, name')
.order('id', { ascending: false })
- Limit the number of rows returned
const { data, error } = await dataloom
.from('characters')
.select('name')
.limit(1)
- Limit the query to a range
const { data, error } = await dataloom
.from('countries')
.select('name')
.range(0, 1)
- Retrieve one row of data
const { data, error } = await dataloom
.from('characters')
.select('name')
.limit(1)
.single()
- Retrieve zero or one row of data
const { data, error } = await dataloom
.from('characters')
.select()
.eq('name', 'Katniss')
.maybeSingle()
Acknowledgements
This project references the implementation of @supabase/supabase-js.
@supabase/supabase-js is licensed under the MIT License.
5 months ago
6 months ago
6 months ago
6 months ago
6 months ago