@tableland/jeti (JavaScript Extension for Tableland Integrations)
A TypeScript/JavaScript library for inserting and extracting IPFS data to and from Tableland queries using the @tableland/sdk
.
Table of Contents
Background
The Tableland project provides a zero-config Typescript/Javascript SDK that make it easy to interact with the Tableland network from Ethereum-based applications. The @tableland/jeti
SDK builds on that, allow you to easily add IPFS data to tableland, and read the data from tableland.
Simply import the library, connect to the Tableland network, and you are ready to start creating and updating tables.
Install
Installation is easy using npm or yarn. An ES bundle is also available for those operating purely in a browser environment.
npm i @tableland/jeti
Note: Not seeing the build type you need for your project or idea? Let us know, we're happy to work with you to improve the SDK usability!
Usage
Pin to IPFS
In this example, using pinToLocal
as a tagged template will insert the proper values in your statement, while simultaneously uploading files to your remote pinning services.
Using the resolve
function of pinToLocal
fetches the data from IPFS into the result set.
import { Database } from "@tableland/sdk";
import { pinToLocal, skip } from "@tableland/jeti";
const db = new Database();
const query = await pinToLocal`INSERT INTO MyTable_31337_1 (id, file) values (1, '${file}');`
db.prepare(query).all();
const resultSet = await db.prepare("SELECT * FROM MyTable_31337_1;").all();
const { rows, columns } = await pinToLocal.resolve(resultSet, ["file"]);
Create your own
import { createProcessor } from '@tableland/jeti';
import { createProcessor } from "@tableland/jeti";
import { ipfsPin, ipfsFetch } from "some-custom-ipfs-lib";
const ipfs = createProcessor(ipfsPin, ipfsFetch);
const db = new Database();
const message = getFile();
const image = getImage();
const query = await ipfs`
INSERT
INTO MyTable_31337_1
(id, message, image)
values
(
0,
'${message}',
'${image}'
)`;
This would use your implementations of the asynchronous functions which are used in the template. The functions can have side effects. The only rule is they might ultimately return a string.
More uses
More uses can be found in our docs
Feedback
Reach out with feedback and ideas:
Maintainers
@awmuncy
Contributing
PRs accepted.
To get started clone this repo, then do:
npm install
npm run build
npm test
Small note: If editing the README, please conform to the
standard-readme specification.
License
MIT AND Apache-2.0, © 2021-2022 Tableland Network Contributors