@apibara/plugin-drizzle 2.1.0-beta.4 → 2.1.0-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +261 -64
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +166 -4
- package/dist/index.d.mts +166 -4
- package/dist/index.d.ts +166 -4
- package/dist/index.mjs +250 -56
- package/dist/index.mjs.map +1 -0
- package/dist/shared/plugin-drizzle.2d226351.mjs +6 -0
- package/dist/shared/plugin-drizzle.2d226351.mjs.map +1 -0
- package/dist/shared/plugin-drizzle.cae20704.cjs +10 -0
- package/dist/shared/plugin-drizzle.cae20704.cjs.map +1 -0
- package/dist/testing.cjs +14 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +6 -0
- package/dist/testing.d.mts +6 -0
- package/dist/testing.d.ts +6 -0
- package/dist/testing.mjs +12 -0
- package/dist/testing.mjs.map +1 -0
- package/package.json +21 -6
- package/src/constants.ts +3 -0
- package/src/helper.ts +219 -0
- package/src/index.ts +160 -18
- package/src/persistence.ts +60 -18
- package/src/storage.ts +88 -23
- package/src/testing.ts +13 -0
- package/src/utils.ts +19 -0
package/src/testing.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { VcrResult } from "@apibara/indexer/testing";
|
|
2
|
+
import type { PgDatabase, PgQueryResultHKT } from "drizzle-orm/pg-core";
|
|
3
|
+
import { DRIZZLE_STORAGE_DB_PROPERTY } from "./constants";
|
|
4
|
+
|
|
5
|
+
export function getTestDatabase(context: VcrResult) {
|
|
6
|
+
const db = context[DRIZZLE_STORAGE_DB_PROPERTY];
|
|
7
|
+
|
|
8
|
+
if (!db) {
|
|
9
|
+
throw new Error("Drizzle database not found in context");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return db as PgDatabase<PgQueryResultHKT>;
|
|
13
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -48,3 +48,22 @@ export function serialize<T>(obj: T): string {
|
|
|
48
48
|
export function sleep(ms: number) {
|
|
49
49
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
50
50
|
}
|
|
51
|
+
|
|
52
|
+
export interface IdColumnMap extends Record<string, string> {
|
|
53
|
+
/**
|
|
54
|
+
* Wildcard mapping for all tables.
|
|
55
|
+
*/
|
|
56
|
+
"*": string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const getIdColumnForTable = (
|
|
60
|
+
tableName: string,
|
|
61
|
+
idColumn: IdColumnMap,
|
|
62
|
+
): string => {
|
|
63
|
+
// If there's a specific mapping for this table, use it
|
|
64
|
+
if (idColumn[tableName]) {
|
|
65
|
+
return idColumn[tableName];
|
|
66
|
+
}
|
|
67
|
+
// Default fallback
|
|
68
|
+
return idColumn["*"];
|
|
69
|
+
};
|