Isomorphic Javascript client for dataloom
``sh`
npm install @data-loom/js
`js
import { createClient } from '@data-loom/js'
// Create a single dataloom client for interacting with your database
const dataloom = createClient(url, key, workspace, {
global: {
brandName: 'abc', // assigned by dataloom
appId: 'app_xyz', // application id created by consumer
},
});
`
`js`
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. |
`js
const { error } = await dataloom
.from('countries')
.insert({ id: 1, name: 'Mordor' })
`
参数
| 参数名称 | 必需 | 类型 | 描述 |
| -------- | ----| ------ | ---- |
| values | Required | Row Array | 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. |
`js
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. |
`js
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. |
* Column is equal to a value
`js`
const { data, error } = await dataloom
.from('characters')
.select()
.eq('name', 'Leia')
* Column is not equal to a value
`js`
const { data, error } = await dataloom
.from('characters')
.select()
.neq('name', 'Leia')
* Column is greater than a value
`js`
const { data, error } = await dataloom
.from('characters')
.select()
.gt('id', 2)
* Column is greater than or equal to a value
`js`
const { data, error } = await dataloom
.from('characters')
.select()
.gte('id', 2)
* Column is less than a value
`js`
const { data, error } = await dataloom
.from('characters')
.select()
.lt('id', 2)
* Column is less than or equal to a value
`js`
const { data, error } = await dataloom
.from('characters')
.select()
.lte('id', 2)
* Column matches a pattern
`js`
const { data, error } = await dataloom
.from('characters')
.select()
.like('name', '%Lu%')
* Column matches a case-insensitive pattern
`js`
const { data, error } = await dataloom
.from('characters')
.select()
.ilike('name', '%lu%')
* Column is a value
`js`
const { data, error } = await dataloom
.from('countries')
.select()
.is('name', null)
* Column is in an array
`js`
const { data, error } = await dataloom
.from('characters')
.select()
.in('name', ['Leia', 'Han'])
* Match an associated value
`js`
const { data, error } = await dataloom
.from('characters')
.select('name')
.match({ id: 2, name: 'Leia' })
* Don't match the filter
`js`
const { data, error } = await dataloom
.from('countries')
.select()
.not('name', 'is', null)
* Don't match the filter
`js`
const { data, error } = await dataloom
.from('characters')
.select('name')
.or('id.eq.2,name.eq.Han')
* Match the filter
`js`
const { data, error } = await dataloom
.from('characters')
.select()
.filter('name', 'in', '("Han","Yoda")')
* Order the results
`js`
const { data, error } = await dataloom
.from('characters')
.select('id, name')
.order('id', { ascending: false })
* Limit the number of rows returned
`js`
const { data, error } = await dataloom
.from('characters')
.select('name')
.limit(1)
* Limit the query to a range
`js`
const { data, error } = await dataloom
.from('countries')
.select('name')
.range(0, 1)
* Retrieve one row of data
`js`
const { data, error } = await dataloom
.from('characters')
.select('name')
.limit(1)
.single()
* Retrieve zero or one row of data
`js``
const { data, error } = await dataloom
.from('characters')
.select()
.eq('name', 'Katniss')
.maybeSingle()
This project references the implementation of @supabase/supabase-js.
@supabase/supabase-js is licensed under the MIT License.