Initial experiments getting pglite working

This commit is contained in:
Matt Aitken
2024-11-19 12:09:27 +00:00
parent 58861a0983
commit fb14f43264
4 changed files with 94 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
import { PGliteWorker } from "@electric-sql/pglite/worker";
export async function pglite() {
return await PGliteWorker.create(
new Worker(new URL("./worker.js", import.meta.url), {
type: "module",
}),
{}
);
}
+76
View File
@@ -0,0 +1,76 @@
import { PGlite } from "@electric-sql/pglite";
import { worker } from "@electric-sql/pglite/worker";
worker({
async init(options) {
const db = new PGlite("idb://triggerdotdev", {
relaxedDurability: true,
...options,
});
await db.exec(`
DROP TYPE IF EXISTS "public"."TaskRunStatus";
CREATE TYPE "public"."TaskRunStatus" AS ENUM ('PENDING', 'EXECUTING', 'WAITING_TO_RESUME', 'RETRYING_AFTER_FAILURE', 'PAUSED', 'CANCELED', 'COMPLETED_SUCCESSFULLY', 'COMPLETED_WITH_ERRORS', 'INTERRUPTED', 'SYSTEM_FAILURE', 'CRASHED', 'WAITING_FOR_DEPLOY', 'DELAYED', 'EXPIRED', 'TIMED_OUT');
CREATE TABLE "public"."TaskRun" (
"id" text NOT NULL,
"idempotencyKey" text,
"payload" text NOT NULL,
"payloadType" text NOT NULL DEFAULT 'application/json'::text,
"context" jsonb,
"runtimeEnvironmentId" text NOT NULL,
"projectId" text NOT NULL,
"createdAt" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" timestamp NOT NULL,
"taskIdentifier" text NOT NULL,
"lockedAt" timestamp,
"lockedById" text,
"friendlyId" text NOT NULL,
"lockedToVersionId" text,
"traceContext" jsonb,
"spanId" text NOT NULL,
"traceId" text NOT NULL,
"concurrencyKey" text,
"queue" text NOT NULL,
"number" int4 NOT NULL DEFAULT 0,
"isTest" bool NOT NULL DEFAULT false,
"status" "public"."TaskRunStatus" NOT NULL DEFAULT 'PENDING'::"TaskRunStatus",
"scheduleId" text,
"scheduleInstanceId" text,
"startedAt" timestamp,
"usageDurationMs" int4 NOT NULL DEFAULT 0,
"costInCents" float8 NOT NULL DEFAULT 0,
"baseCostInCents" float8 NOT NULL DEFAULT 0,
"machinePreset" text,
"delayUntil" timestamp,
"queuedAt" timestamp,
"expiredAt" timestamp,
"ttl" text,
"maxAttempts" int4,
"completedAt" timestamp,
"logsDeletedAt" timestamp,
"batchId" text,
"depth" int4 NOT NULL DEFAULT 0,
"parentTaskRunAttemptId" text,
"parentTaskRunId" text,
"resumeParentOnCompletion" bool NOT NULL DEFAULT false,
"rootTaskRunId" text,
"parentSpanId" text,
"metadata" text,
"metadataType" text NOT NULL DEFAULT 'application/json'::text,
"output" text,
"outputType" text NOT NULL DEFAULT 'application/json'::text,
"error" jsonb,
"seedMetadata" text,
"seedMetadataType" text NOT NULL DEFAULT 'application/json'::text,
"runTags" _text,
"maxDurationInSeconds" int4,
CONSTRAINT "TaskRun_parentTaskRunId_fkey" FOREIGN KEY ("parentTaskRunId") REFERENCES "public"."TaskRun"("id") ON DELETE SET NULL,
CONSTRAINT "TaskRun_rootTaskRunId_fkey" FOREIGN KEY ("rootTaskRunId") REFERENCES "public"."TaskRun"("id") ON DELETE SET NULL,
PRIMARY KEY ("id")
);
`);
return db;
},
});
+1
View File
@@ -46,6 +46,7 @@
"@conform-to/react": "^0.6.1",
"@conform-to/zod": "^0.6.1",
"@depot/sdk-node": "^1.0.0",
"@electric-sql/pglite": "^0.2.13",
"@electric-sql/react": "^0.3.5",
"@headlessui/react": "^1.7.8",
"@heroicons/react": "^2.0.12",
+7
View File
@@ -231,6 +231,9 @@ importers:
'@depot/sdk-node':
specifier: ^1.0.0
version: 1.0.0
'@electric-sql/pglite':
specifier: ^0.2.13
version: 0.2.13
'@electric-sql/react':
specifier: ^0.3.5
version: 0.3.5(react@18.2.0)
@@ -4809,6 +4812,10 @@ packages:
'@rollup/rollup-darwin-arm64': 4.21.3
dev: false
/@electric-sql/pglite@0.2.13:
resolution: {integrity: sha512-YRY806NnScVqa21/1L1vaysSQ+0/cAva50z7vlwzaGiBOTS9JhdzIRHN0KfgMhobFAphbznZJ7urMso4RtMBIQ==}
dev: false
/@electric-sql/react@0.3.5(react@18.2.0):
resolution: {integrity: sha512-qPrlF3BsRg5L8zAn1sLGzc3pkswfEHyQI3lNOu7Xllv1DBx85RvHR1zgGGPAUfC8iwyWupQu9pFPE63GdbeuhA==}
peerDependencies: