Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom pin function #45

Merged
merged 4 commits into from
May 11, 2023
Merged

Custom pin function #45

merged 4 commits into from
May 11, 2023

Conversation

awmuncy
Copy link
Contributor

@awmuncy awmuncy commented May 5, 2023

By default, JETI uses your local IPFS node and errors out if you don't have a remote pinning service connected. This meant you could only work with the "standardized" IPFS pinning API. But that isn't fully supported everywhere. So if you want to set up your own pin function, you can do that now, like so:

import { setup } from '@tableland/jeti';

setup({
   pin: async (content) => {
          let { cid } = pinContentToMyService(content);
          return {
              cid,
              pinned: true
         }
   }
)

prepare`INSERT INTO TABLE (id, name) values (5, '${new TextEncoder().encode("Hi there")}')`;

@awmuncy awmuncy requested a review from dtbuchholz May 5, 2023 17:49
@awmuncy awmuncy changed the base branch from main to staging May 5, 2023 17:49
@carsonfarmer
Copy link
Member

How robust is that prepare tooling? Should we move it into core js-tableland?

@awmuncy
Copy link
Contributor Author

awmuncy commented May 5, 2023

How robust is that prepare tooling? Should we move it into core js-tableland?

I think naming it "prepare" is a bit of a misnomer, and I think I'm going to rename it to "process". So probably not robust for the uses of which you're thinking.

Though in the next iteration maybe? I'm actually rethinking JETI's premise. "JavaScript Extension for Tableland and IPFS". Tableland queries with IPFS? Great! But really, it could be even better. And more simple. If we just use a custom process function and custom resolve function, both of which the user can specficy, we can make it "JavaScript Extension for Tableland Integrations" or something.
You can do something like

import { setup } from '@tableland/sdk';
setup({
   processor: (content) => {
        return await addContentToIpfsAndReturnCid(content);
   }
});

db.prepare(await process`INSERT INTO mytable (id, avatar) values ('1', ${avatar})`).run();

and the process tagged template could add it to IPFS. Alternatively, it could turn it to base64, or encrypt it, or... well, do anything you want.

Same concept with resolve, except it would be

// Custom resolve funtion
resolver(cell) {
     if(cell.column==="avatar") {
         return await resolveFromIpfs(cell.content);
     } 
     return cell.content;
}

// Elsewhere
resolve(db.prepare("SELECT id, name from table;").all());

@dtbuchholz
Copy link
Contributor

(In general, I think this would be a nice feature as part of the SDK, too. Uploading data to IPFS and storing CIDs in tables is a core use case.)

joewagner
joewagner previously approved these changes May 9, 2023
@joewagner joewagner changed the base branch from staging to main May 11, 2023 15:22
@joewagner joewagner dismissed their stale review May 11, 2023 15:22

The base branch was changed.

@joewagner joewagner changed the base branch from main to staging May 11, 2023 15:31
@joewagner joewagner self-requested a review May 11, 2023 21:55
Copy link
Contributor

@joewagner joewagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like my approval got wiped when I updated the staging branch. Approving again

@awmuncy awmuncy merged commit 13606f8 into staging May 11, 2023
@joewagner joewagner deleted the custom-pin-function branch May 30, 2023 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants