Unigraph SQL Examples
These examples show the same queries two ways: in raw SQL (any PostgreSQL client, any language) and with the typed @ensnode/ensdb-sdk for TypeScript projects.
SQL access requires connecting to your own self-hosted ENSDb instance.
Using the Unigraph SQL requires that you have the unigraph plugin activated in your ENSNode instance. Learn more
Connect
Section titled “Connect”The Unigraph lives in ENSDb, a PostgreSQL database. Each ENSIndexer instance writes to its own ENSIndexer Schema (e.g. ensindexer_0); shared operational metadata lives in the ensnode schema.
psql postgresql://user:password@host:5432/ensdb_devnetDiscover the available ENSIndexer Schemas:
SELECT DISTINCT ens_indexer_schema_nameFROM ensnode.metadata;npm install @ensnode/ensdb-sdkThe EnsDbReader object enables you to build custom queries against the Unigraph data model in ENSDb. Use the ensDb field to build queries with the Drizzle ORM, and the ensIndexerSchema field to reference database objects (i.e. the Unigraph tables) within the ENSIndexer Schema in a type-safe way.
import { EnsDbReader } from "@ensnode/ensdb-sdk";
// Connect by providing a connection string and the ENSIndexer Schema Name to queryconst ensDbReader = new EnsDbReader(ensDbConnectionString, ensIndexerSchemaName);const { ensDb, ensIndexerSchema } = ensDbReader;