@effect/sql-pg
Advanced tools
| /** | ||
| * @since 1.0.0 | ||
| */ | ||
| import type * as Effect from "effect/Effect"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as FileSystem from "effect/FileSystem"; | ||
| import * as Layer from "effect/Layer"; | ||
| import * as Path from "effect/Path"; | ||
| import type * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner"; | ||
| import * as Migrator from "effect/unstable/sql/Migrator"; | ||
| import type * as Client from "effect/unstable/sql/SqlClient"; | ||
| import type { SqlClient } from "effect/unstable/sql/SqlClient"; | ||
| import type { SqlError } from "effect/unstable/sql/SqlError"; | ||
| import { PgClient } from "./PgClient.ts"; | ||
| /** | ||
@@ -17,3 +21,3 @@ * @since 1.0.0 | ||
| */ | ||
| export declare const run: <R2 = never>(options: Migrator.MigratorOptions<R2>) => Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, Migrator.MigrationError | SqlError, Client.SqlClient | R2>; | ||
| export declare const run: <R2 = never>(options: Migrator.MigratorOptions<R2>) => Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, Migrator.MigrationError | SqlError, SqlClient | PgClient | ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem | Path.Path | R2>; | ||
| /** | ||
@@ -23,3 +27,3 @@ * @category layers | ||
| */ | ||
| export declare const layer: <R>(options: Migrator.MigratorOptions<R>) => Layer.Layer<never, Migrator.MigrationError | SqlError, Client.SqlClient | R>; | ||
| export declare const layer: <R>(options: Migrator.MigratorOptions<R>) => Layer.Layer<never, Migrator.MigrationError | SqlError, SqlClient | PgClient | ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem | Path.Path | R>; | ||
| //# sourceMappingURL=PgMigrator.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"PgMigrator.d.ts","sourceRoot":"","sources":["../src/PgMigrator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,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8BAA8B,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC;;GAEG;AACH,cAAc,8BAA8B,CAAA;AAE5C;;;GAGG;AACH,eAAO,MAAM,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,EAC3B,OAAO,EAAE,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,KAClC,MAAM,CAAC,MAAM,CAChB,aAAa,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,EAClD,QAAQ,CAAC,cAAc,GAAG,QAAQ,EAChC,SAAS,GACT,QAAQ,GACR,mBAAmB,CAAC,mBAAmB,GACvC,UAAU,CAAC,UAAU,GACrB,IAAI,CAAC,IAAI,GACT,EAAE,CAuDJ,CAAA;AAEF;;;GAGG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EACrB,SAAS,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,KACnC,KAAK,CAAC,KAAK,CACZ,KAAK,EACL,QAAQ,CAAC,cAAc,GAAG,QAAQ,EAChC,SAAS,GACT,QAAQ,GACR,mBAAmB,CAAC,mBAAmB,GACvC,UAAU,CAAC,UAAU,GACrB,IAAI,CAAC,IAAI,GACT,CAAC,CACiC,CAAA"} |
+47
-56
@@ -0,3 +1,12 @@ | ||
| /** | ||
| * @since 1.0.0 | ||
| */ | ||
| import * as Effect from "effect/Effect"; | ||
| import * as FileSystem from "effect/FileSystem"; | ||
| import * as Layer from "effect/Layer"; | ||
| import * as Path from "effect/Path"; | ||
| import * as Redacted from "effect/Redacted"; | ||
| import * as ChildProcess from "effect/unstable/process/ChildProcess"; | ||
| import * as Migrator from "effect/unstable/sql/Migrator"; | ||
| import { PgClient } from "./PgClient.js"; | ||
| /** | ||
@@ -12,58 +21,40 @@ * @since 1.0.0 | ||
| export const run = /*#__PURE__*/Migrator.make({ | ||
| // TODO: Wait for Command module | ||
| // dumpSchema(path, table) { | ||
| // const pgDump = (args: Array<string>) => | ||
| // Effect.gen(function*() { | ||
| // const sql = yield* PgClient | ||
| // const dump = yield* pipe( | ||
| // Command.make("pg_dump", ...args, "--no-owner", "--no-privileges"), | ||
| // Command.env({ | ||
| // PATH: (globalThis as any).process?.env.PATH, | ||
| // PGHOST: sql.config.host, | ||
| // PGPORT: sql.config.port?.toString(), | ||
| // PGUSER: sql.config.username, | ||
| // PGPASSWORD: sql.config.password | ||
| // ? Redacted.value(sql.config.password) | ||
| // : undefined, | ||
| // PGDATABASE: sql.config.database, | ||
| // PGSSLMODE: sql.config.ssl ? "require" : "prefer" | ||
| // }), | ||
| // Command.string | ||
| // ) | ||
| // | ||
| // return dump.replace(/^--.*$/gm, "") | ||
| // .replace(/^SET .*$/gm, "") | ||
| // .replace(/^SELECT pg_catalog\..*$/gm, "") | ||
| // .replace(/\n{2,}/gm, "\n\n") | ||
| // .trim() | ||
| // }).pipe( | ||
| // Effect.mapError((error) => new Migrator.MigrationError({ kind: "Failed", message: error.message })) | ||
| // ) | ||
| // | ||
| // const pgDumpSchema = pgDump(["--schema-only"]) | ||
| // | ||
| // const pgDumpMigrations = pgDump([ | ||
| // "--column-inserts", | ||
| // "--data-only", | ||
| // `--table=${table}` | ||
| // ]) | ||
| // | ||
| // const pgDumpAll = Effect.map( | ||
| // Effect.all([pgDumpSchema, pgDumpMigrations], { concurrency: 2 }), | ||
| // ([schema, migrations]) => schema + "\n\n" + migrations | ||
| // ) | ||
| // | ||
| // const pgDumpFile = (path: string) => | ||
| // Effect.gen(function*() { | ||
| // const fs = yield* FileSystem | ||
| // const path_ = yield* Path | ||
| // const dump = yield* pgDumpAll | ||
| // yield* fs.makeDirectory(path_.dirname(path), { recursive: true }) | ||
| // yield* fs.writeFileString(path, dump) | ||
| // }).pipe( | ||
| // Effect.mapError((error) => new Migrator.MigrationError({ kind: "Failed", message: error.message })) | ||
| // ) | ||
| // | ||
| // return pgDumpFile(path) | ||
| // } | ||
| dumpSchema(path, table) { | ||
| const pgDump = args => Effect.gen(function* () { | ||
| const sql = yield* PgClient; | ||
| const dump = yield* ChildProcess.make("pg_dump", [...args, "--no-owner", "--no-privileges"], { | ||
| env: { | ||
| PATH: globalThis.process?.env.PATH, | ||
| PGHOST: sql.config.host, | ||
| PGPORT: sql.config.port?.toString(), | ||
| PGUSER: sql.config.username, | ||
| PGPASSWORD: sql.config.password ? Redacted.value(sql.config.password) : undefined, | ||
| PGDATABASE: sql.config.database, | ||
| PGSSLMODE: sql.config.ssl ? "require" : "prefer" | ||
| } | ||
| }).pipe(ChildProcess.string); | ||
| return dump.replace(/^--.*$/gm, "").replace(/^SET .*$/gm, "").replace(/^SELECT pg_catalog\..*$/gm, "").replace(/\n{2,}/gm, "\n\n").trim(); | ||
| }).pipe(Effect.mapError(error => new Migrator.MigrationError({ | ||
| kind: "Failed", | ||
| message: error.message | ||
| }))); | ||
| const pgDumpSchema = pgDump(["--schema-only"]); | ||
| const pgDumpMigrations = pgDump(["--column-inserts", "--data-only", `--table=${table}`]); | ||
| const pgDumpAll = Effect.map(Effect.all([pgDumpSchema, pgDumpMigrations], { | ||
| concurrency: 2 | ||
| }), ([schema, migrations]) => schema + "\n\n" + migrations); | ||
| const pgDumpFile = path => Effect.gen(function* () { | ||
| const fs = yield* FileSystem.FileSystem; | ||
| const path_ = yield* Path.Path; | ||
| const dump = yield* pgDumpAll; | ||
| yield* fs.makeDirectory(path_.dirname(path), { | ||
| recursive: true | ||
| }); | ||
| yield* fs.writeFileString(path, dump); | ||
| }).pipe(Effect.mapError(error => new Migrator.MigrationError({ | ||
| kind: "Failed", | ||
| message: error.message | ||
| }))); | ||
| return pgDumpFile(path); | ||
| } | ||
| }); | ||
@@ -70,0 +61,0 @@ /** |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"PgMigrator.js","names":["Layer","Migrator","run","make","layer","options","effectDiscard"],"sources":["../src/PgMigrator.ts"],"sourcesContent":[null],"mappings":"AAIA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,QAAQ,MAAM,8BAA8B;AAIxD;;;AAGA,cAAc,8BAA8B;AAE5C;;;;AAIA,OAAO,MAAMC,GAAG,gBAMZD,QAAQ,CAACE,IAAI,CAAC;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;AAAA,CACD,CAAC;AAEF;;;;AAIA,OAAO,MAAMC,KAAK,GAChBC,OAAoC,IAKjCL,KAAK,CAACM,aAAa,CAACJ,GAAG,CAACG,OAAO,CAAC,CAAC","ignoreList":[]} | ||
| {"version":3,"file":"PgMigrator.js","names":["Effect","FileSystem","Layer","Path","Redacted","ChildProcess","Migrator","PgClient","run","make","dumpSchema","path","table","pgDump","args","gen","sql","dump","env","PATH","globalThis","process","PGHOST","config","host","PGPORT","port","toString","PGUSER","username","PGPASSWORD","password","value","undefined","PGDATABASE","database","PGSSLMODE","ssl","pipe","string","replace","trim","mapError","error","MigrationError","kind","message","pgDumpSchema","pgDumpMigrations","pgDumpAll","map","all","concurrency","schema","migrations","pgDumpFile","fs","path_","makeDirectory","dirname","recursive","writeFileString","layer","options","effectDiscard"],"sources":["../src/PgMigrator.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,UAAU,MAAM,mBAAmB;AAC/C,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,YAAY,MAAM,sCAAsC;AAEpE,OAAO,KAAKC,QAAQ,MAAM,8BAA8B;AAG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,IAAI,CAAC;EACzB;CACD,CAAC;AAEF;;;;AAIA,OAAO,MAAMmD,KAAK,GAChBC,OAAoC,IAUjC7D,KAAK,CAAC8D,aAAa,CAACxD,GAAG,CAACuD,OAAO,CAAC,CAAC","ignoreList":[]} |
+3
-3
| { | ||
| "name": "@effect/sql-pg", | ||
| "version": "4.0.0-beta.7", | ||
| "version": "4.0.0-beta.8", | ||
| "type": "module", | ||
@@ -49,6 +49,6 @@ "license": "MIT", | ||
| "@types/pg-cursor": "^2.7.2", | ||
| "effect": "^4.0.0-beta.7" | ||
| "effect": "^4.0.0-beta.8" | ||
| }, | ||
| "peerDependencies": { | ||
| "effect": "^4.0.0-beta.7" | ||
| "effect": "^4.0.0-beta.8" | ||
| }, | ||
@@ -55,0 +55,0 @@ "dependencies": { |
+73
-60
| /** | ||
| * @since 1.0.0 | ||
| */ | ||
| import type * as Effect from "effect/Effect" | ||
| import * as Effect from "effect/Effect" | ||
| import * as FileSystem from "effect/FileSystem" | ||
| import * as Layer from "effect/Layer" | ||
| import * as Path from "effect/Path" | ||
| import * as Redacted from "effect/Redacted" | ||
| import * as ChildProcess from "effect/unstable/process/ChildProcess" | ||
| import type * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner" | ||
| import * as Migrator from "effect/unstable/sql/Migrator" | ||
| import type * as Client from "effect/unstable/sql/SqlClient" | ||
| import type { SqlClient } from "effect/unstable/sql/SqlClient" | ||
| import type { SqlError } from "effect/unstable/sql/SqlError" | ||
| import { PgClient } from "./PgClient.ts" | ||
@@ -24,60 +30,62 @@ /** | ||
| Migrator.MigrationError | SqlError, | ||
| Client.SqlClient | R2 | ||
| | SqlClient | ||
| | PgClient | ||
| | ChildProcessSpawner.ChildProcessSpawner | ||
| | FileSystem.FileSystem | ||
| | Path.Path | ||
| | R2 | ||
| > = Migrator.make({ | ||
| // TODO: Wait for Command module | ||
| // dumpSchema(path, table) { | ||
| // const pgDump = (args: Array<string>) => | ||
| // Effect.gen(function*() { | ||
| // const sql = yield* PgClient | ||
| // const dump = yield* pipe( | ||
| // Command.make("pg_dump", ...args, "--no-owner", "--no-privileges"), | ||
| // Command.env({ | ||
| // PATH: (globalThis as any).process?.env.PATH, | ||
| // PGHOST: sql.config.host, | ||
| // PGPORT: sql.config.port?.toString(), | ||
| // PGUSER: sql.config.username, | ||
| // PGPASSWORD: sql.config.password | ||
| // ? Redacted.value(sql.config.password) | ||
| // : undefined, | ||
| // PGDATABASE: sql.config.database, | ||
| // PGSSLMODE: sql.config.ssl ? "require" : "prefer" | ||
| // }), | ||
| // Command.string | ||
| // ) | ||
| // | ||
| // return dump.replace(/^--.*$/gm, "") | ||
| // .replace(/^SET .*$/gm, "") | ||
| // .replace(/^SELECT pg_catalog\..*$/gm, "") | ||
| // .replace(/\n{2,}/gm, "\n\n") | ||
| // .trim() | ||
| // }).pipe( | ||
| // Effect.mapError((error) => new Migrator.MigrationError({ kind: "Failed", message: error.message })) | ||
| // ) | ||
| // | ||
| // const pgDumpSchema = pgDump(["--schema-only"]) | ||
| // | ||
| // const pgDumpMigrations = pgDump([ | ||
| // "--column-inserts", | ||
| // "--data-only", | ||
| // `--table=${table}` | ||
| // ]) | ||
| // | ||
| // const pgDumpAll = Effect.map( | ||
| // Effect.all([pgDumpSchema, pgDumpMigrations], { concurrency: 2 }), | ||
| // ([schema, migrations]) => schema + "\n\n" + migrations | ||
| // ) | ||
| // | ||
| // const pgDumpFile = (path: string) => | ||
| // Effect.gen(function*() { | ||
| // const fs = yield* FileSystem | ||
| // const path_ = yield* Path | ||
| // const dump = yield* pgDumpAll | ||
| // yield* fs.makeDirectory(path_.dirname(path), { recursive: true }) | ||
| // yield* fs.writeFileString(path, dump) | ||
| // }).pipe( | ||
| // Effect.mapError((error) => new Migrator.MigrationError({ kind: "Failed", message: error.message })) | ||
| // ) | ||
| // | ||
| // return pgDumpFile(path) | ||
| // } | ||
| dumpSchema(path, table) { | ||
| const pgDump = (args: Array<string>) => | ||
| Effect.gen(function*() { | ||
| const sql = yield* PgClient | ||
| const dump = yield* ChildProcess.make("pg_dump", [...args, "--no-owner", "--no-privileges"], { | ||
| env: { | ||
| PATH: (globalThis as any).process?.env.PATH, | ||
| PGHOST: sql.config.host, | ||
| PGPORT: sql.config.port?.toString(), | ||
| PGUSER: sql.config.username, | ||
| PGPASSWORD: sql.config.password | ||
| ? Redacted.value(sql.config.password) | ||
| : undefined, | ||
| PGDATABASE: sql.config.database, | ||
| PGSSLMODE: sql.config.ssl ? "require" : "prefer" | ||
| } | ||
| }).pipe(ChildProcess.string) | ||
| return dump.replace(/^--.*$/gm, "") | ||
| .replace(/^SET .*$/gm, "") | ||
| .replace(/^SELECT pg_catalog\..*$/gm, "") | ||
| .replace(/\n{2,}/gm, "\n\n") | ||
| .trim(); | ||
| }).pipe( | ||
| Effect.mapError((error) => new Migrator.MigrationError({ kind: "Failed", message: error.message })) | ||
| ) | ||
| const pgDumpSchema = pgDump(["--schema-only"]) | ||
| const pgDumpMigrations = pgDump([ | ||
| "--column-inserts", | ||
| "--data-only", | ||
| `--table=${table}` | ||
| ]) | ||
| const pgDumpAll = Effect.map( | ||
| Effect.all([pgDumpSchema, pgDumpMigrations], { concurrency: 2 }), | ||
| ([schema, migrations]) => schema + "\n\n" + migrations | ||
| ) | ||
| const pgDumpFile = (path: string) => | ||
| Effect.gen(function*() { | ||
| const fs = yield* FileSystem.FileSystem | ||
| const path_ = yield* Path.Path | ||
| const dump = yield* pgDumpAll | ||
| yield* fs.makeDirectory(path_.dirname(path), { recursive: true }) | ||
| yield* fs.writeFileString(path, dump) | ||
| }).pipe( | ||
| Effect.mapError((error) => new Migrator.MigrationError({ kind: "Failed", message: error.message })) | ||
| ) | ||
| return pgDumpFile(path) | ||
| } | ||
| }) | ||
@@ -94,3 +102,8 @@ | ||
| Migrator.MigrationError | SqlError, | ||
| Client.SqlClient | R | ||
| | SqlClient | ||
| | PgClient | ||
| | ChildProcessSpawner.ChildProcessSpawner | ||
| | FileSystem.FileSystem | ||
| | Path.Path | ||
| | R | ||
| > => Layer.effectDiscard(run(options)) |
76102
4.71%1303
0.23%