Install airtable-dnd
using npm or yarn
# install using npm
npm install airtable-dnd
# install using yarn
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
.
airtable-dnd
vs. Deno version
fetch
on instantiation options (see “Polyfilling fetch
”)airtable-deno
where it’s using private identifiers (#options
)airtable-dnd
vs. first-party Node.js version
fetch
implementation (see “Polyfilling fetch
”)Collaborators
, MultipleSelect<T>
, etc.)new Airtable()
instead of new Airtable().base()().select()...
)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",
]);
For advanced examples, refer to the airtable-deno
examples file.
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({
// no need to pass `fetch` since it's polyfilled globally
});
Polyfill prioritization
By default, airtable-dnd
will use the fetch
object passed from the instantiation option, then fallbacks to the global fetch
object.
All options, parameters, errors, and responses are the same as on the Airtable API documentation.
cross-fetch
: https://github.com/lquixada/cross-fetchAuthor: grikomsn
Source Code: https://github.com/grikomsn/airtable-dnd
#deno #nodejs #node #javascript