Install
Install airtable-dnd
using npm or yarn
npm install airtable-dnd
yarn add airtable-dnd
â Important note: airtable-dnd
internally uses fetch
and assumes it exists â
If you're on an environment that already has fetch
(Next.js runtimes, browsers, etc.), airtable-dnd
will use that.
If you're on an environment that does not have fetch
, refer to the "Polyfilling fetch
" section on how to implement or bring your own fetch
.
Comparison
airtable-dnd
vs. Deno version
- Accepts custom
fetch
on instantiation options (see "Polyfilling fetch
") - Instance options are exposed unlike
airtable-deno
where it's using private identifiers (#options
)
airtable-dnd
vs. first-party Node.js version
- Does not ship with
fetch
implementation (see "Polyfilling fetch
") - First-class support for generic field types with extra field types (
Collaborators
, MultipleSelect<T>
, etc.) - Single object instance (
new Airtable()
instead of new Airtable().base()().select()...
)
Basic examples
Instantiate Airtable client
import { Airtable } from "airtable-dnd";
const airtable = new Airtable({
apiKey: "keyXXXXXXXXXXXXXX",
baseId: "appXXXXXXXXXXXXXX",
tableName: "Some table name",
});
Select record(s)
const results = await airtable.select();
Creating record(s)
const createOne = await airtable.create({
Name: "Griko Nibras",
Age: 25,
});
import { Field } from "airtable-dnd";
type Fields = {
Name: string;
Age: number;
Active?: Field.Checkbox;
};
const createMultiple = await airtable.create<Fields>(
[
{ Name: "Foo", Age: 20 },
{ Name: "Bar", Age: 15 },
],
{ typecast: true },
);
Updating record(s)
const updateOne = await airtable.update<Fields>("recXXXXXXXXXXXXXX", {
Name: "Adult boi",
Age: 30,
});
const updateMultiple = await airtable.update<Fields>(
[
{
id: "recXXXXXXXXXXXXXX",
fields: { Name: "Adult boi", Age: 30 },
},
{
id: "recXXXXXXXXXXXXXX",
fields: { Name: "Yung boi", Age: 15 },
},
],
{ typecast: true },
);
Delete record(s)
const deleteOne = await airtable.delete("recXXXXXXXXXXXXXX");
const deleteMultiple = await airtable.delete([
"recXXXXXXXXXXXXXX",
"recXXXXXXXXXXXXXX",
]);
Advanced examples
For advanced examples, refer to the airtable-deno
examples file.
Polyfilling fetch
Since Node.js does not have built-in fetch
implementation unlike Deno, airtable-dnd
has two ways to implement/polyfill fetch
.
Polyfill methods
-
Pass fetch
compliant object to client instantiation
airtable-dnd
has cross-fetch
as a peer dependency for polyfilling, but you can use other fetch
compliant packages (node-fetch
, whatwg-fetch
, isomorphic-fetch
, etc.), you can import and pass the fetch
object on client instantiation.
import fetch from "node-fetch";
const airtable = new Airtable({
fetch,
});
-
Polyfill fetch
globally
Alternatively, you can do a global polyfill with cross-fetch/polyfill
or other fetch
compliant packages that supports global polyfilling before instantiating or calling the Airtable client.
import "cross-fetch/polyfill";
const airtable = new Airtable({
});
Polyfill prioritization
By default, airtable-dnd
will use the fetch
object passed from the instantiation option, then fallbacks to the global fetch
object.
Further reading
All options, parameters, errors, and responses are the same as on the Airtable API documentation.
Dependencies
License
MIT License Copyright (c) 2020 Griko Nibras