atable-lite
v1.0.2
Published
## 导入 1. 先在 airtable 控制台创建好要导入的 table 和 field。 2. 在控制台获取自己的 apiKey 和对应 table 的 baseId。 3. 使用 `Table.import` 导入
Downloads
6
Readme
#airtable-admin
导入
- 先在 airtable 控制台创建好要导入的 table 和 field。
- 在控制台获取自己的 apiKey 和对应 table 的 baseId。
- 使用
Table.import
导入
const fields = ['cate', 'ele', 'startdate'] // 字段名称
// 导入的数据
const records = [
[],
['🔥 Weekly Top 10 Custom Wordles'],
['🔥 Weekly Top 10 Custom Wordles', 'girls'],
['🔥 Weekly Top 10 Custom Wordles', ''],
['🏀 NBA Teams', 'nets'],
['🏀 NBA Teams', 'celtics'],
['', 'bull', '2022-12-01'],
['😭 Hardest 10 Wordles in Unlimited:', 'abcd3', '2010', ''],
]
Table.import({
apiKey, baseId, name: tableName, fields, records
}).then(() => console.log('导入成功'))
API
Table
假设 table kv
里面的数据如下:
| cate | ele | | ---- | ---- | | 🔥 Weekly Top 10 Custom Wordles | girls | | 🔥 Weekly Top 10 Custom Wordles | ukraine | | 🏀 NBA Teams | celtics | | 😭 Hardest 10 Wordles in Unlimited | ashed | | 🔥 Weekly Top 10 Custom Wordles | wordle | | 😭 Hardest 10 Wordles in Unlimited | abcde | | 🏀 NBA Teams | nets |
需要事先知道自己操作的 apiKey
, baseId
import { Table } from 'airtable'
const USER_API_KEY = 'xxx'
const BASE_ID = 'baseid'
const table = new Table({ baseId: BASE_ID, apiKey: USER_API_KEY, name: 'kv' })
// 也可以全局配置 apiKey
Table.configureApiKey(USER_API_KEY)
const table = new Table({ baseId: BASE_ID})
findAll
返回表中所有的数据行
table.findAll().then((records) => console.log(records))
[
{
"cate": "🔥 Weekly Top 10 Custom Wordles",
"ele": "girls"
},
{
"cate": "🔥 Weekly Top 10 Custom Wordles",
"ele": "ukraine"
},
{
"cate": "😭 Hardest 10 Wordles in Unlimited:",
"ele": "ashed"
},
{
"cate": "🏀 NBA Teams",
"ele": "nets"
},
{
"cate": "😭 Hardest 10 Wordles in Unlimited:",
"ele": "abcde"
},
{
"cate": "🔥 Weekly Top 10 Custom Wordles",
"ele": "wordle"
},
{
"cate": "🏀 NBA Teams",
"ele": "celtics"
}
]
removeAll
删除表中所有的数据
table.removeAll().then(() => console.log('success'))
find
接收一个 where
条件,返回满足所有对应字段的条件的数据行。
type WhereCondition = Record<string, string | RegExp>
table.find({ cate: 'Top 10', ele: /a/}).then((records) => console.log(records))
[
{
"cate": "🔥 Weekly Top 10 Custom Wordles", // '🔥 Weekly Top 10 Custom Wordles' 满足 'Top 10'
"ele": "ukraine" // 'ukraine' 满足 /a/
}
]
groupBy
根据字段名,将表中的数据分组。
table.groupBy('cate').then((groups) => console.log(groups))
{
"🔥 Weekly Top 10 Custom Wordles": [
{
"cate": "🔥 Weekly Top 10 Custom Wordles",
"ele": "girls"
},
{
"cate": "🔥 Weekly Top 10 Custom Wordles",
"ele": "ukraine"
},
{
"cate": "🔥 Weekly Top 10 Custom Wordles",
"ele": "wordle"
}
],
"😭 Hardest 10 Wordles in Unlimited:": [
{
"cate": "😭 Hardest 10 Wordles in Unlimited:",
"ele": "ashed"
},
{
"cate": "😭 Hardest 10 Wordles in Unlimited:",
"ele": "abcde"
}
],
"🏀 NBA Teams": [
{
"cate": "🏀 NBA Teams",
"ele": "nets"
},
{
"cate": "🏀 NBA Teams",
"ele": "celtics"
}
]
}
Table.import
向表中导入数据
Table.import(opts)
// opts 的类型为
{
apiKey: string,
baseId: string,
name: string, // 要导入的表名
fields: string[], // 导入的字段名称列表 ['cate', 'ele']
records: string[][], // 导入的数据 [['aa', '11']['bb', '22']]
}