@llllvvuu/subsquid-drizzle-store
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

@llllvvuu/subsquid-drizzle-store

pnpm install @llllvvuu/subsquid-drizzle-store

Caveats:

  • Only supports Postgres
  • Does not support hot blocks

Example

import { DrizzleDatabase } from '@llllvvuu/subsquid-drizzle-store'
import { drizzle } from 'drizzle-orm/node-postgres'
import { numeric, pgTable, text, varchar } from 'drizzle-orm/pg-core'
import pg from 'pg'
const { Client } = pg

const client = new Client({ connectionString: process.env['DB_URL'] })
await client.connect()
export const db = drizzle(client)

export const transfer = pgTable('transfer', {
  id: varchar('id').primaryKey(),
  from: text('from').notNull(),
  to: text('to').notNull(),
  value: numeric('value').notNull(),
})

// ...

const store = new DrizzleDatabase(db)
processor.run(store, async ctx => {
  const transfers: { id: string; from: string; to: string; value: string }[] =
    []
  for (let block of ctx.blocks) {
    for (let log of block.logs) {
      let { from, to, value } = usdtAbi.events.Transfer.decode(log)
      transfers.push({
        id: log.id,
        from,
        to,
        value: String(value),
      })
    }
  }
  if (transfers.length === 0) return
  await ctx.store.insert(transfer).values(transfers)
})

Readme

Keywords

none

Package Sidebar

Install

npm i @llllvvuu/subsquid-drizzle-store

Weekly Downloads

0

Version

0.1.3

License

MIT

Unpacked Size

27.6 kB

Total Files

7

Last publish

Collaborators

  • llllvvuu