Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Aug 23, 2023
1 parent f280a7a commit 8213907
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions packages/store-sync/src/postgres/postgresStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ describe("postgresStorage", async () => {
});

it("should create tables and data from block log", async () => {
const adapter = await postgresStorage({ database: db, publicClient });
const storage = await postgresStorage({ database: db, publicClient });

await blockLogsToStorage(adapter)({
await blockLogsToStorage(storage)({
blockNumber: 5448n,
logs: [
{
Expand Down Expand Up @@ -73,7 +73,7 @@ describe("postgresStorage", async () => {
],
});

expect(await db.select().from(adapter.internalTables.chain)).toMatchInlineSnapshot(`
expect(await db.select().from(storage.internalTables.chain)).toMatchInlineSnapshot(`
[
{
"chainId": 31337,
Expand All @@ -84,7 +84,7 @@ describe("postgresStorage", async () => {
]
`);

expect(await db.select().from(adapter.internalTables.tables)).toMatchInlineSnapshot(`
expect(await db.select().from(storage.internalTables.tables)).toMatchInlineSnapshot(`
[
{
"address": "0x5FbDB2315678afecb367f032d93F642f64180aa3",
Expand Down Expand Up @@ -132,6 +132,6 @@ describe("postgresStorage", async () => {
const sqlTable = createTable(tables[0]);
expect(await db.select().from(sqlTable)).toMatchInlineSnapshot("[]");

await adapter.cleanUp();
await storage.cleanUp();
});
});
8 changes: 4 additions & 4 deletions packages/store-sync/src/postgres/postgresStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { getTableKey } from "./getTableKey";

// Currently assumes one DB per chain ID

type PostgresStorageAdapter<TConfig extends StoreConfig> = BlockLogsToStorageOptions<TConfig> & {
type PostgresStorage<TConfig extends StoreConfig> = BlockLogsToStorageOptions<TConfig> & {
internalTables: ReturnType<typeof createInternalTables>;
cleanUp: () => Promise<void>;
};
Expand All @@ -28,15 +28,15 @@ export async function postgresStorage<TConfig extends StoreConfig = StoreConfig>
database: PgDatabase<QueryResultHKT>;
publicClient: PublicClient;
config?: TConfig;
}): Promise<PostgresStorageAdapter<TConfig>> {
}): Promise<PostgresStorage<TConfig>> {
const cleanUp: (() => Promise<void>)[] = [];

const chainId = publicClient.chain?.id ?? (await publicClient.getChainId());

const internalTables = createInternalTables();
cleanUp.push(await setupTables(database, Object.values(internalTables)));

const adapter = {
const storage = {
async registerTables({ blockNumber, tables }) {
const sqlTables = tables.map((table) =>
createTable({
Expand Down Expand Up @@ -185,7 +185,7 @@ export async function postgresStorage<TConfig extends StoreConfig = StoreConfig>
} as BlockLogsToStorageOptions<TConfig>;

return {
...adapter,
...storage,
internalTables,
cleanUp: async (): Promise<void> => {
for (const fn of cleanUp) {
Expand Down

0 comments on commit 8213907

Please sign in to comment.