0.2.32 • Published 7 months ago

@theo-dev/airtable-connect v0.2.32

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

Airtable Configuration

This package is used to configure the Airtable integration for your project.

New Features!

In this version, you can now use readByID function to get a record by ID. I work on a new version to add more features. If you have any suggestions, please contact me.

Getting Started

Installation

npm install --save @theo-dev/airtable-connect

Create a .env file in the root of your project and add the following:

# If you use React, you can add the following to your .env file
REACT_APP_AIRTABLE_PERSONNAL_TOKEN=
REACT_APP_AIRTABLE_BASE_ID=

# If you use Vite, you can add the following to your .env file
VITE_AIRTABLE_PERSONNAL_TOKEN=
VITE_AIRTABLE_BASE_ID=

 

Usage

  • Connection to Airtable

    // If you create a .env file, you can use the following code to connect to Airtable
    import { AirtableConnect } from "@theo-dev/airtable-connect";
    
    const { AirtableData } = AirtableConnect;
    
    const tableInstance = new AirtableData(
      "Table Name",
      "View Name (optional if you want to use the default view)"
    );
    // If you don't create a .env file, you can use the following code to connect to Airtable
    import { AirtableConnect } from "@theo-dev/airtable-connect";
    
    const { AirtableConfig, AirtableData } = AirtableConnect;
    
    AirtableConfig.getBase("Personnal Token", "Base ID");
    
    const tableInstance = new AirtableData(
      "Table Name",
      "View Name (optional if you want to use the default view)"
    );
  • Retrieving Datas

    Add function in parameter of read function to get datas like this:

    let datas = [];
    
    tableInstance.read({
      action: (dataset) => {
        datas = dataset;
      },
      completedOnly: true, // optional - if you want to get only completed records
    });
  • Retrieving data by ID

    Add function in parameter of readByID function to get data like this:

    let data = null;
    
    tableInstance.readByID({
      id: "RECORD_ID",
      action: (dataset) => {
        data = dataset;
      },
    });
  • Creating Data

    // Create a record
    
    tableInstance.create({
      datas: { "Field Name": "Field Value" },
    }); // return nothing just create the record

    You can also add function in parameter of create function to get the data like this:

    let newRecord = [];
    
    tableInstance.create({
      datas: { "Field Name": "Field Value" },
      action: (record) => {
        newRecord = record;
      },
    }); // return nothing just create the record and add the new record in newRecord variable
  • Updating Data

    // Update a record
    tableInstance.update({
      datas: { id: "ExampleID", fields: { FieldName: "Field Value" } },
    }); // return nothing just update the record
    
    // Update multiple records
    
    const records = [
      {
        id: "ExampleID",
        fields: { FieldName: "Field Value" },
      },
      {
        id: "ExampleID",
        fields: { FieldName: "Field Value" },
      },
    ];
    
    tableInstance.update({
      datas: records,
    }); // return nothing just update records

    You can also add function in parameter of update function to get the data like this:

    let updatedRecord = [];
    
    tableInstance.update({
      datas: { id: "ExampleID", fields: { FieldName: "Field Value" } },
      action: (record) => {
        updatedRecord = record;
      },
    });
  • Deleting Data

    Add function in parameter of delete function to get the deleted data like this:

    let deletedRecord = [];
    
    tableInstance.delete({
      id: "ExampleID",
      action: (record) => {
        deletedRecord = record;
      },
    });

Package Dependencies

Airtable TypeScript

Credits

0.2.27

7 months ago

0.2.25

7 months ago

0.2.22

7 months ago

0.2.21

7 months ago

0.2.13

7 months ago

0.2.11

7 months ago

0.2.32

7 months ago

0.2.31

7 months ago

0.2.29

7 months ago

0.2.3

7 months ago

0.2.5

7 months ago

0.2.2

11 months ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.8

1 year ago

0.1.9

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago