@payloadcms/db-postgres 3.0.0-canary.fb81f02 → 3.0.0-canary.ff8c8fd
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +45 -2
- package/dist/connect.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -15
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +9 -116
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +7 -8
- package/dist/connectionHelpers/nodePostgres.d.ts +0 -11
- package/dist/connectionHelpers/nodePostgres.d.ts.map +0 -1
- package/dist/connectionHelpers/nodePostgres.js +0 -6
- package/dist/connectionHelpers/nodePostgres.js.map +0 -1
- package/dist/countDistinct.d.ts +0 -3
- package/dist/countDistinct.d.ts.map +0 -1
- package/dist/countDistinct.js +0 -24
- package/dist/countDistinct.js.map +0 -1
- package/dist/createJSONQuery/convertPathToJSONTraversal.d.ts +0 -2
- package/dist/createJSONQuery/convertPathToJSONTraversal.d.ts.map +0 -1
- package/dist/createJSONQuery/convertPathToJSONTraversal.js +0 -14
- package/dist/createJSONQuery/convertPathToJSONTraversal.js.map +0 -1
- package/dist/createJSONQuery/formatJSONPathSegment.d.ts +0 -2
- package/dist/createJSONQuery/formatJSONPathSegment.d.ts.map +0 -1
- package/dist/createJSONQuery/formatJSONPathSegment.js +0 -5
- package/dist/createJSONQuery/formatJSONPathSegment.js.map +0 -1
- package/dist/createJSONQuery/index.d.ts +0 -10
- package/dist/createJSONQuery/index.d.ts.map +0 -1
- package/dist/createJSONQuery/index.js +0 -54
- package/dist/createJSONQuery/index.js.map +0 -1
- package/dist/createMigration.d.ts +0 -3
- package/dist/createMigration.d.ts.map +0 -1
- package/dist/createMigration.js +0 -91
- package/dist/createMigration.js.map +0 -1
- package/dist/defaultSnapshot.d.ts +0 -3
- package/dist/defaultSnapshot.d.ts.map +0 -1
- package/dist/defaultSnapshot.js +0 -17
- package/dist/defaultSnapshot.js.map +0 -1
- package/dist/deleteWhere.d.ts +0 -3
- package/dist/deleteWhere.d.ts.map +0 -1
- package/dist/deleteWhere.js +0 -6
- package/dist/deleteWhere.js.map +0 -1
- package/dist/dropDatabase.d.ts +0 -3
- package/dist/dropDatabase.d.ts.map +0 -1
- package/dist/dropDatabase.js +0 -9
- package/dist/dropDatabase.js.map +0 -1
- package/dist/execute.d.ts +0 -3
- package/dist/execute.d.ts.map +0 -1
- package/dist/execute.js +0 -11
- package/dist/execute.js.map +0 -1
- package/dist/getMigrationTemplate.d.ts +0 -4
- package/dist/getMigrationTemplate.d.ts.map +0 -1
- package/dist/getMigrationTemplate.js +0 -13
- package/dist/getMigrationTemplate.js.map +0 -1
- package/dist/init.d.ts +0 -3
- package/dist/init.d.ts.map +0 -1
- package/dist/init.js +0 -83
- package/dist/init.js.map +0 -1
- package/dist/insert.d.ts +0 -3
- package/dist/insert.d.ts.map +0 -1
- package/dist/insert.js +0 -12
- package/dist/insert.js.map +0 -1
- package/dist/requireDrizzleKit.d.ts +0 -3
- package/dist/requireDrizzleKit.d.ts.map +0 -1
- package/dist/requireDrizzleKit.js +0 -5
- package/dist/requireDrizzleKit.js.map +0 -1
- package/dist/schema/build.d.ts +0 -34
- package/dist/schema/build.d.ts.map +0 -1
- package/dist/schema/build.js +0 -369
- package/dist/schema/build.js.map +0 -1
- package/dist/schema/createIndex.d.ts +0 -12
- package/dist/schema/createIndex.d.ts.map +0 -1
- package/dist/schema/createIndex.js +0 -18
- package/dist/schema/createIndex.js.map +0 -1
- package/dist/schema/idToUUID.d.ts +0 -3
- package/dist/schema/idToUUID.d.ts.map +0 -1
- package/dist/schema/idToUUID.js +0 -11
- package/dist/schema/idToUUID.js.map +0 -1
- package/dist/schema/parentIDColumnMap.d.ts +0 -4
- package/dist/schema/parentIDColumnMap.d.ts.map +0 -1
- package/dist/schema/parentIDColumnMap.js +0 -9
- package/dist/schema/parentIDColumnMap.js.map +0 -1
- package/dist/schema/setColumnID.d.ts +0 -11
- package/dist/schema/setColumnID.d.ts.map +0 -1
- package/dist/schema/setColumnID.js +0 -24
- package/dist/schema/setColumnID.js.map +0 -1
- package/dist/schema/traverseFields.d.ts +0 -36
- package/dist/schema/traverseFields.d.ts.map +0 -1
- package/dist/schema/traverseFields.js +0 -613
- package/dist/schema/traverseFields.js.map +0 -1
- package/dist/schema/withDefault.d.ts +0 -4
- package/dist/schema/withDefault.d.ts.map +0 -1
- package/dist/schema/withDefault.js +0 -10
- package/dist/schema/withDefault.js.map +0 -1
package/dist/connect.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAW,MAAM,SAAS,CAAA;AA6C/C,eAAO,MAAM,OAAO,EAAE,OAmDrB,CAAA"}
|
package/dist/connect.js
CHANGED
@@ -1,4 +1,41 @@
|
|
1
1
|
import { pushDevSchema } from '@payloadcms/drizzle';
|
2
|
+
import { drizzle } from 'drizzle-orm/node-postgres';
|
3
|
+
import pg from 'pg';
|
4
|
+
const connectWithReconnect = async function({ adapter, payload, reconnect = false }) {
|
5
|
+
let result;
|
6
|
+
if (!reconnect) {
|
7
|
+
result = await adapter.pool.connect();
|
8
|
+
} else {
|
9
|
+
try {
|
10
|
+
result = await adapter.pool.connect();
|
11
|
+
} catch (err) {
|
12
|
+
setTimeout(()=>{
|
13
|
+
payload.logger.info('Reconnecting to postgres');
|
14
|
+
void connectWithReconnect({
|
15
|
+
adapter,
|
16
|
+
payload,
|
17
|
+
reconnect: true
|
18
|
+
});
|
19
|
+
}, 1000);
|
20
|
+
}
|
21
|
+
}
|
22
|
+
if (!result) {
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
result.prependListener('error', (err)=>{
|
26
|
+
try {
|
27
|
+
if (err.code === 'ECONNRESET') {
|
28
|
+
void connectWithReconnect({
|
29
|
+
adapter,
|
30
|
+
payload,
|
31
|
+
reconnect: true
|
32
|
+
});
|
33
|
+
}
|
34
|
+
} catch (err) {
|
35
|
+
// swallow error
|
36
|
+
}
|
37
|
+
});
|
38
|
+
};
|
2
39
|
export const connect = async function connect(options = {
|
3
40
|
hotReload: false
|
4
41
|
}) {
|
@@ -10,12 +47,18 @@ export const connect = async function connect(options = {
|
|
10
47
|
...this.enums
|
11
48
|
};
|
12
49
|
try {
|
50
|
+
if (!this.pool) {
|
51
|
+
this.pool = new pg.Pool(this.poolOptions);
|
52
|
+
await connectWithReconnect({
|
53
|
+
adapter: this,
|
54
|
+
payload: this.payload
|
55
|
+
});
|
56
|
+
}
|
13
57
|
const logger = this.logger || false;
|
14
|
-
|
58
|
+
this.drizzle = drizzle(this.pool, {
|
15
59
|
logger,
|
16
60
|
schema: this.schema
|
17
61
|
});
|
18
|
-
this.drizzle = drizzle;
|
19
62
|
if (!hotReload) {
|
20
63
|
if (process.env.PAYLOAD_DROP_DATABASE === 'true') {
|
21
64
|
this.payload.logger.info(`---- DROPPING TABLES SCHEMA(${this.schemaName || 'public'}) ----`);
|
package/dist/connect.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { DrizzleAdapter } from '@payloadcms/drizzle/types'\nimport type { Connect } from 'payload'\n\nimport { pushDevSchema } from '@payloadcms/drizzle'\n\nimport type { PostgresAdapter } from './types.js'\n\nexport const connect: Connect = async function connect(\n this: PostgresAdapter,\n options = {\n hotReload: false,\n },\n) {\n const { hotReload } = options\n\n this.schema = {\n pgSchema: this.pgSchema,\n ...this.tables,\n ...this.relations,\n ...this.enums,\n }\n\n try {\n const logger = this.logger || false\n
|
1
|
+
{"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { DrizzleAdapter } from '@payloadcms/drizzle/types'\nimport type { Connect, Payload } from 'payload'\n\nimport { pushDevSchema } from '@payloadcms/drizzle'\nimport { drizzle } from 'drizzle-orm/node-postgres'\nimport pg from 'pg'\n\nimport type { PostgresAdapter } from './types.js'\n\nconst connectWithReconnect = async function ({\n adapter,\n payload,\n reconnect = false,\n}: {\n adapter: PostgresAdapter\n payload: Payload\n reconnect?: boolean\n}) {\n let result\n\n if (!reconnect) {\n result = await adapter.pool.connect()\n } else {\n try {\n result = await adapter.pool.connect()\n } catch (err) {\n setTimeout(() => {\n payload.logger.info('Reconnecting to postgres')\n void connectWithReconnect({ adapter, payload, reconnect: true })\n }, 1000)\n }\n }\n if (!result) {\n return\n }\n result.prependListener('error', (err) => {\n try {\n if (err.code === 'ECONNRESET') {\n void connectWithReconnect({ adapter, payload, reconnect: true })\n }\n } catch (err) {\n // swallow error\n }\n })\n}\n\nexport const connect: Connect = async function connect(\n this: PostgresAdapter,\n options = {\n hotReload: false,\n },\n) {\n const { hotReload } = options\n\n this.schema = {\n pgSchema: this.pgSchema,\n ...this.tables,\n ...this.relations,\n ...this.enums,\n }\n\n try {\n if (!this.pool) {\n this.pool = new pg.Pool(this.poolOptions)\n await connectWithReconnect({ adapter: this, payload: this.payload })\n }\n\n const logger = this.logger || false\n this.drizzle = drizzle(this.pool, { logger, schema: this.schema })\n\n if (!hotReload) {\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n this.payload.logger.info(`---- DROPPING TABLES SCHEMA(${this.schemaName || 'public'}) ----`)\n await this.dropDatabase({ adapter: this })\n this.payload.logger.info('---- DROPPED TABLES ----')\n }\n }\n } catch (err) {\n this.payload.logger.error(`Error: cannot connect to Postgres. Details: ${err.message}`, err)\n if (typeof this.rejectInitializing === 'function') this.rejectInitializing()\n process.exit(1)\n }\n\n // Only push schema if not in production\n if (\n process.env.NODE_ENV !== 'production' &&\n process.env.PAYLOAD_MIGRATING !== 'true' &&\n this.push !== false\n ) {\n await pushDevSchema(this as unknown as DrizzleAdapter)\n }\n\n if (typeof this.resolveInitializing === 'function') this.resolveInitializing()\n\n if (process.env.NODE_ENV === 'production' && this.prodMigrations) {\n await this.migrate({ migrations: this.prodMigrations })\n }\n}\n"],"names":["pushDevSchema","drizzle","pg","connectWithReconnect","adapter","payload","reconnect","result","pool","connect","err","setTimeout","logger","info","prependListener","code","options","hotReload","schema","pgSchema","tables","relations","enums","Pool","poolOptions","process","env","PAYLOAD_DROP_DATABASE","schemaName","dropDatabase","error","message","rejectInitializing","exit","NODE_ENV","PAYLOAD_MIGRATING","push","resolveInitializing","prodMigrations","migrate","migrations"],"mappings":"AAGA,SAASA,aAAa,QAAQ,sBAAqB;AACnD,SAASC,OAAO,QAAQ,4BAA2B;AACnD,OAAOC,QAAQ,KAAI;AAInB,MAAMC,uBAAuB,eAAgB,EAC3CC,OAAO,EACPC,OAAO,EACPC,YAAY,KAAK,EAKlB;IACC,IAAIC;IAEJ,IAAI,CAACD,WAAW;QACdC,SAAS,MAAMH,QAAQI,IAAI,CAACC,OAAO;IACrC,OAAO;QACL,IAAI;YACFF,SAAS,MAAMH,QAAQI,IAAI,CAACC,OAAO;QACrC,EAAE,OAAOC,KAAK;YACZC,WAAW;gBACTN,QAAQO,MAAM,CAACC,IAAI,CAAC;gBACpB,KAAKV,qBAAqB;oBAAEC;oBAASC;oBAASC,WAAW;gBAAK;YAChE,GAAG;QACL;IACF;IACA,IAAI,CAACC,QAAQ;QACX;IACF;IACAA,OAAOO,eAAe,CAAC,SAAS,CAACJ;QAC/B,IAAI;YACF,IAAIA,IAAIK,IAAI,KAAK,cAAc;gBAC7B,KAAKZ,qBAAqB;oBAAEC;oBAASC;oBAASC,WAAW;gBAAK;YAChE;QACF,EAAE,OAAOI,KAAK;QACZ,gBAAgB;QAClB;IACF;AACF;AAEA,OAAO,MAAMD,UAAmB,eAAeA,QAE7CO,UAAU;IACRC,WAAW;AACb,CAAC;IAED,MAAM,EAAEA,SAAS,EAAE,GAAGD;IAEtB,IAAI,CAACE,MAAM,GAAG;QACZC,UAAU,IAAI,CAACA,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AAI,CAACqC,mBAAmB,KAAK,YAAY,IAAI,CAACA,mBAAmB;IAE5E,IAAIZ,QAAQC,GAAG,CAACQ,QAAQ,KAAK,gBAAgB,IAAI,CAACI,cAAc,EAAE;QAChE,MAAM,IAAI,CAACC,OAAO,CAAC;YAAEC,YAAY,IAAI,CAACF,cAAc;QAAC;IACvD;AACF,EAAC"}
|
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import type { DatabaseAdapterObj } from 'payload';
|
2
|
-
export { nodePostgres } from './connectionHelpers/nodePostgres.js';
|
3
2
|
import type { Args, PostgresAdapter } from './types.js';
|
4
|
-
export type { MigrateDownArgs, MigrateUpArgs } from './types.js';
|
5
|
-
export { sql } from 'drizzle-orm';
|
6
3
|
export declare function postgresAdapter(args: Args): DatabaseAdapterObj<PostgresAdapter>;
|
4
|
+
export type { MigrateDownArgs, MigrateUpArgs } from '@payloadcms/drizzle/postgres';
|
5
|
+
export { sql } from 'drizzle-orm';
|
7
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAW,MAAM,SAAS,CAAA;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAW,MAAM,SAAS,CAAA;AAmD1D,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAIvD,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,kBAAkB,CAAC,eAAe,CAAC,CAwG/E;AAED,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAClF,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/index.js
CHANGED
@@ -1,21 +1,8 @@
|
|
1
|
-
export { nodePostgres } from './connectionHelpers/nodePostgres.js';
|
2
1
|
import { beginTransaction, commitTransaction, count, create, createGlobal, createGlobalVersion, createVersion, deleteMany, deleteOne, deleteVersions, destroy, find, findGlobal, findGlobalVersions, findMigrationDir, findOne, findVersions, migrate, migrateDown, migrateFresh, migrateRefresh, migrateReset, migrateStatus, operatorMap, queryDrafts, rollbackTransaction, updateGlobal, updateGlobalVersion, updateOne, updateVersion } from '@payloadcms/drizzle';
|
2
|
+
import { convertPathToJSONTraversal, countDistinct, createJSONQuery, createMigration, defaultDrizzleSnapshot, deleteWhere, dropDatabase, execute, getMigrationTemplate, init, insert, requireDrizzleKit } from '@payloadcms/drizzle/postgres';
|
3
3
|
import { pgEnum, pgSchema, pgTable } from 'drizzle-orm/pg-core';
|
4
4
|
import { createDatabaseAdapter } from 'payload';
|
5
5
|
import { connect } from './connect.js';
|
6
|
-
import { countDistinct } from './countDistinct.js';
|
7
|
-
import { convertPathToJSONTraversal } from './createJSONQuery/convertPathToJSONTraversal.js';
|
8
|
-
import { createJSONQuery } from './createJSONQuery/index.js';
|
9
|
-
import { createMigration } from './createMigration.js';
|
10
|
-
import { defaultDrizzleSnapshot } from './defaultSnapshot.js';
|
11
|
-
import { deleteWhere } from './deleteWhere.js';
|
12
|
-
import { dropDatabase } from './dropDatabase.js';
|
13
|
-
import { execute } from './execute.js';
|
14
|
-
import { getMigrationTemplate } from './getMigrationTemplate.js';
|
15
|
-
import { init } from './init.js';
|
16
|
-
import { insert } from './insert.js';
|
17
|
-
import { requireDrizzleKit } from './requireDrizzleKit.js';
|
18
|
-
export { sql } from 'drizzle-orm';
|
19
6
|
export function postgresAdapter(args) {
|
20
7
|
const postgresIDType = args.idType || 'serial';
|
21
8
|
const payloadIDType = postgresIDType === 'serial' ? 'number' : 'text';
|
@@ -45,7 +32,6 @@ export function postgresAdapter(args) {
|
|
45
32
|
json: true
|
46
33
|
},
|
47
34
|
fieldConstraints: {},
|
48
|
-
getDrizzle: args.getDrizzle,
|
49
35
|
getMigrationTemplate,
|
50
36
|
idType: postgresIDType,
|
51
37
|
initializing,
|
@@ -54,6 +40,7 @@ export function postgresAdapter(args) {
|
|
54
40
|
operators: operatorMap,
|
55
41
|
pgSchema: adapterSchema,
|
56
42
|
pool: undefined,
|
43
|
+
poolOptions: args.pool,
|
57
44
|
prodMigrations: args.prodMigrations,
|
58
45
|
push: args.push,
|
59
46
|
relations: {},
|
@@ -100,6 +87,7 @@ export function postgresAdapter(args) {
|
|
100
87
|
migrateReset,
|
101
88
|
migrateStatus,
|
102
89
|
migrationDir,
|
90
|
+
packageName: '@payloadcms/db-postgres',
|
103
91
|
payload,
|
104
92
|
queryDrafts,
|
105
93
|
rejectInitializing,
|
@@ -117,5 +105,6 @@ export function postgresAdapter(args) {
|
|
117
105
|
init: adapter
|
118
106
|
};
|
119
107
|
}
|
108
|
+
export { sql } from 'drizzle-orm';
|
120
109
|
|
121
110
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { DatabaseAdapterObj, Payload } from 'payload'\n\
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { DatabaseAdapterObj, Payload } from 'payload'\n\nimport {\n beginTransaction,\n commitTransaction,\n count,\n create,\n createGlobal,\n createGlobalVersion,\n createVersion,\n deleteMany,\n deleteOne,\n deleteVersions,\n destroy,\n find,\n findGlobal,\n findGlobalVersions,\n findMigrationDir,\n findOne,\n findVersions,\n migrate,\n migrateDown,\n migrateFresh,\n migrateRefresh,\n migrateReset,\n migrateStatus,\n operatorMap,\n queryDrafts,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n} from '@payloadcms/drizzle'\nimport {\n convertPathToJSONTraversal,\n countDistinct,\n createJSONQuery,\n createMigration,\n defaultDrizzleSnapshot,\n deleteWhere,\n dropDatabase,\n execute,\n getMigrationTemplate,\n init,\n insert,\n requireDrizzleKit,\n} from '@payloadcms/drizzle/postgres'\nimport { pgEnum, pgSchema, pgTable } from 'drizzle-orm/pg-core'\nimport { createDatabaseAdapter } from 'payload'\n\nimport type { Args, PostgresAdapter } from './types.js'\n\nimport { connect } from './connect.js'\n\nexport function postgresAdapter(args: Args): DatabaseAdapterObj<PostgresAdapter> {\n const postgresIDType = args.idType || 'serial'\n const payloadIDType = postgresIDType === 'serial' ? 'number' : 'text'\n\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(args.migrationDir)\n let resolveInitializing\n let rejectInitializing\n let adapterSchema: PostgresAdapter['pgSchema']\n\n const initializing = new Promise<void>((res, rej) => {\n resolveInitializing = res\n rejectInitializing = rej\n })\n\n if (args.schemaName) {\n adapterSchema = pgSchema(args.schemaName)\n } else {\n adapterSchema = { enum: pgEnum, table: pgTable }\n }\n\n return createDatabaseAdapter<PostgresAdapter>({\n name: 'postgres',\n defaultDrizzleSnapshot,\n drizzle: undefined,\n enums: {},\n features: {\n json: true,\n },\n fieldConstraints: {},\n getMigrationTemplate,\n idType: postgresIDType,\n initializing,\n localesSuffix: args.localesSuffix || '_locales',\n logger: args.logger,\n operators: operatorMap,\n pgSchema: adapterSchema,\n pool: undefined,\n poolOptions: args.pool,\n prodMigrations: args.prodMigrations,\n push: args.push,\n relations: {},\n relationshipsSuffix: args.relationshipsSuffix || '_rels',\n schema: {},\n schemaName: args.schemaName,\n sessions: {},\n tableNameMap: new Map<string, string>(),\n tables: {},\n transactionOptions: args.transactionOptions || undefined,\n versionsSuffix: args.versionsSuffix || '_v',\n\n // DatabaseAdapter\n beginTransaction: args.transactionOptions === false ? undefined : beginTransaction,\n commitTransaction,\n connect,\n convertPathToJSONTraversal,\n count,\n countDistinct,\n create,\n createGlobal,\n createGlobalVersion,\n createJSONQuery,\n createMigration,\n createVersion,\n defaultIDType: payloadIDType,\n deleteMany,\n deleteOne,\n deleteVersions,\n deleteWhere,\n destroy,\n dropDatabase,\n execute,\n find,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n init,\n insert,\n migrate,\n migrateDown,\n migrateFresh,\n migrateRefresh,\n migrateReset,\n migrateStatus,\n migrationDir,\n packageName: '@payloadcms/db-postgres',\n payload,\n queryDrafts,\n rejectInitializing,\n requireDrizzleKit,\n resolveInitializing,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n })\n }\n\n return {\n defaultIDType: payloadIDType,\n init: adapter,\n }\n}\n\nexport type { MigrateDownArgs, MigrateUpArgs } from '@payloadcms/drizzle/postgres'\nexport { sql } from 'drizzle-orm'\n"],"names":["beginTransaction","commitTransaction","count","create","createGlobal","createGlobalVersion","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findMigrationDir","findOne","findVersions","migrate","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","operatorMap","queryDrafts","rollbackTransaction","updateGlobal","updateGlobalVersion","updateOne","updateVersion","convertPathToJSONTraversal","countDistinct","createJSONQuery","createMigration","defaultDrizzleSnapshot","deleteWhere","dropDatabase","execute","getMigrationTemplate","init","insert","requireDrizzleKit","pgEnum","pgSchema","pgTable","createDatabaseAdapter","connect","postgresAdapter","args","postgresIDType","idType","payloadIDType","adapter","payload","migrationDir","resolveInitializing","rejectInitializing","adapterSchema","initializing","Promise","res","rej","schemaName","enum","table","name","drizzle","undefined","enums","features","json","fieldConstraints","localesSuffix","logger","operators","pool","poolOptions","prodMigrations","push","relations","relationshipsSuffix","schema","sessions","tableNameMap","Map","tables","transactionOptions","versionsSuffix","defaultIDType","packageName","sql"],"mappings":"AAEA,SACEA,gBAAgB,EAChBC,iBAAiB,EACjBC,KAAK,EACLC,MAAM,EACNC,YAAY,EACZC,mBAAmB,EACnBC,aAAa,EACbC,UAAU,EACVC,SAAS,EACTC,cAAc,EACdC,OAAO,EACPC,IAAI,EACJC,UAAU,EACVC,kBAAkB,EA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WnD;YACXoB,UAAUc;YACVkB,MAAMR;YACNS,aAAa5B,KAAK2B,IAAI;YACtBE,gBAAgB7B,KAAK6B,cAAc;YACnCC,MAAM9B,KAAK8B,IAAI;YACfC,WAAW,CAAC;YACZC,qBAAqBhC,KAAKgC,mBAAmB,IAAI;YACjDC,QAAQ,CAAC;YACTnB,YAAYd,KAAKc,UAAU;YAC3BoB,UAAU,CAAC;YACXC,cAAc,IAAIC;YAClBC,QAAQ,CAAC;YACTC,oBAAoBtC,KAAKsC,kBAAkB,IAAInB;YAC/CoB,gBAAgBvC,KAAKuC,cAAc,IAAI;YAEvC,kBAAkB;YAClBvF,kBAAkBgD,KAAKsC,kBAAkB,KAAK,QAAQnB,YAAYnE;YAClEC;YACA6C;YACAhB;YACA5B;YACA6B;YACA5B;YACAC;YACAC;YACA2B;YACAC;YACA3B;YACAkF,eAAerC;YACf5C;YACAC;YACAC;YACA0B;YACAzB;YACA0B;YACAC;YACA1B;YACAC;YACAC;YACAE;YACAC;YACAuB;YACAC;YACAvB;YACAC;YACAC;YACAC;YACAC;YACAC;YACAgC;YACAmC,aAAa;YACbpC;YACA7B;YACAgC;YACAf;YACAc;YACA9B;YACAC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAO;QACL2D,eAAerC;QACfZ,MAAMa;IACR;AACF;AAGA,SAASsC,GAAG,QAAQ,cAAa"}
|
package/dist/types.d.ts
CHANGED
@@ -1,21 +1,14 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
import type {
|
5
|
-
import type {
|
6
|
-
import type { PgColumn, PgEnum, PgInsertOnConflictDoUpdateConfig, PgSchema, PgTableWithColumns, PgTransactionConfig, pgEnum } from 'drizzle-orm/pg-core';
|
7
|
-
import type { PgTableFn } from 'drizzle-orm/pg-core/table';
|
8
|
-
import type { Payload, PayloadRequest } from 'payload';
|
9
|
-
import type { Pool, QueryResult } from 'pg';
|
1
|
+
import type { BasePostgresAdapter, GenericEnum, MigrateDownArgs, MigrateUpArgs, PostgresDB } from '@payloadcms/drizzle/postgres';
|
2
|
+
import type { DrizzleAdapter } from '@payloadcms/drizzle/types';
|
3
|
+
import type { DrizzleConfig } from 'drizzle-orm';
|
4
|
+
import type { PgSchema, PgTableFn, PgTransactionConfig } from 'drizzle-orm/pg-core';
|
5
|
+
import type { Pool, PoolConfig } from 'pg';
|
10
6
|
export type Args = {
|
11
|
-
/**
|
12
|
-
* A function that connects to the database and returns the drizzle instance
|
13
|
-
*/
|
14
|
-
getDrizzle: PostgresAdapter['getDrizzle'];
|
15
7
|
idType?: 'serial' | 'uuid';
|
16
8
|
localesSuffix?: string;
|
17
9
|
logger?: DrizzleConfig['logger'];
|
18
10
|
migrationDir?: string;
|
11
|
+
pool: PoolConfig;
|
19
12
|
prodMigrations?: {
|
20
13
|
down: (args: MigrateDownArgs) => Promise<void>;
|
21
14
|
name: string;
|
@@ -31,110 +24,10 @@ export type Args = {
|
|
31
24
|
transactionOptions?: PgTransactionConfig | false;
|
32
25
|
versionsSuffix?: string;
|
33
26
|
};
|
34
|
-
export type GenericColumn = PgColumn<ColumnBaseConfig<ColumnDataType, string>, Record<string, unknown>>;
|
35
|
-
export type GenericColumns = {
|
36
|
-
[x: string]: GenericColumn;
|
37
|
-
};
|
38
|
-
export type GenericTable = PgTableWithColumns<{
|
39
|
-
columns: GenericColumns;
|
40
|
-
dialect: string;
|
41
|
-
name: string;
|
42
|
-
schema: string;
|
43
|
-
}>;
|
44
|
-
export type GenericEnum = PgEnum<[string, ...string[]]>;
|
45
|
-
export type GenericRelation = Relations<string, Record<string, Relation<string>>>;
|
46
|
-
export type PostgresDB = NodePgDatabase<Record<string, unknown>>;
|
47
|
-
export type CountDistinct = (args: {
|
48
|
-
db: PostgresDB | TransactionPg;
|
49
|
-
joins: BuildQueryJoinAliases;
|
50
|
-
tableName: string;
|
51
|
-
where: SQL;
|
52
|
-
}) => Promise<number>;
|
53
|
-
export type DeleteWhere = (args: {
|
54
|
-
db: PostgresDB | TransactionPg;
|
55
|
-
tableName: string;
|
56
|
-
where: SQL;
|
57
|
-
}) => Promise<void>;
|
58
|
-
export type DropDatabase = (args: {
|
59
|
-
adapter: PostgresAdapter;
|
60
|
-
}) => Promise<void>;
|
61
|
-
export type Execute<T> = (args: {
|
62
|
-
db?: PostgresDB | TransactionPg;
|
63
|
-
drizzle?: PostgresDB;
|
64
|
-
raw?: string;
|
65
|
-
sql?: SQL<unknown>;
|
66
|
-
}) => Promise<QueryResult<Record<string, T>>>;
|
67
|
-
export type Insert = (args: {
|
68
|
-
db: PostgresDB | TransactionPg;
|
69
|
-
onConflictDoUpdate?: PgInsertOnConflictDoUpdateConfig<any>;
|
70
|
-
tableName: string;
|
71
|
-
values: Record<string, unknown> | Record<string, unknown>[];
|
72
|
-
}) => Promise<Record<string, unknown>[]>;
|
73
|
-
type PostgresDrizzleAdapter = Omit<DrizzleAdapter, 'countDistinct' | 'deleteWhere' | 'drizzle' | 'dropDatabase' | 'execute' | 'insert' | 'operators' | 'relations'>;
|
74
|
-
type Schema = {
|
75
|
-
enum: typeof pgEnum;
|
76
|
-
table: PgTableFn;
|
77
|
-
} | PgSchema;
|
78
27
|
export type PostgresAdapter = {
|
79
|
-
countDistinct: CountDistinct;
|
80
|
-
defaultDrizzleSnapshot: DrizzleSnapshotJSON;
|
81
|
-
deleteWhere: DeleteWhere;
|
82
|
-
drizzle: PostgresDB;
|
83
|
-
dropDatabase: DropDatabase;
|
84
|
-
enums: Record<string, GenericEnum>;
|
85
|
-
execute: Execute<unknown>;
|
86
|
-
/**
|
87
|
-
* An object keyed on each table, with a key value pair where the constraint name is the key, followed by the dot-notation field name
|
88
|
-
* Used for returning properly formed errors from unique fields
|
89
|
-
*/
|
90
|
-
fieldConstraints: Record<string, Record<string, string>>;
|
91
|
-
/**
|
92
|
-
* A function that connects to the database and returns the drizzle instance
|
93
|
-
*/
|
94
|
-
getDrizzle: (args: Pick<DrizzleConfig<Record<string, unknown>>, 'logger' | 'schema'>) => {
|
95
|
-
drizzle: PostgresDB | TransactionPg;
|
96
|
-
} | Promise<{
|
97
|
-
drizzle: PostgresDB | TransactionPg;
|
98
|
-
}>;
|
99
|
-
idType: Args['idType'];
|
100
|
-
initializing: Promise<void>;
|
101
|
-
insert: Insert;
|
102
|
-
localesSuffix?: string;
|
103
|
-
logger: DrizzleConfig['logger'];
|
104
|
-
operators: Operators;
|
105
|
-
pgSchema?: Schema;
|
106
28
|
pool: Pool;
|
107
|
-
|
108
|
-
|
109
|
-
name: string;
|
110
|
-
up: (args: MigrateUpArgs) => Promise<void>;
|
111
|
-
}[];
|
112
|
-
push: boolean;
|
113
|
-
rejectInitializing: () => void;
|
114
|
-
relations: Record<string, GenericRelation>;
|
115
|
-
relationshipsSuffix?: string;
|
116
|
-
resolveInitializing: () => void;
|
117
|
-
schemaName?: Args['schemaName'];
|
118
|
-
sessions: {
|
119
|
-
[id: string]: {
|
120
|
-
db: PostgresDB | TransactionPg;
|
121
|
-
reject: () => Promise<void>;
|
122
|
-
resolve: () => Promise<void>;
|
123
|
-
};
|
124
|
-
};
|
125
|
-
tableNameMap: Map<string, string>;
|
126
|
-
tables: Record<string, GenericTable>;
|
127
|
-
versionsSuffix?: string;
|
128
|
-
} & PostgresDrizzleAdapter;
|
129
|
-
export type IDType = 'integer' | 'numeric' | 'uuid' | 'varchar';
|
130
|
-
export type MigrateUpArgs = {
|
131
|
-
payload: Payload;
|
132
|
-
req?: Partial<PayloadRequest>;
|
133
|
-
};
|
134
|
-
export type MigrateDownArgs = {
|
135
|
-
payload: Payload;
|
136
|
-
req?: Partial<PayloadRequest>;
|
137
|
-
};
|
29
|
+
poolOptions: PoolConfig;
|
30
|
+
} & BasePostgresAdapter;
|
138
31
|
declare module 'payload' {
|
139
32
|
interface DatabaseAdapter extends Omit<Args, 'idType' | 'logger' | 'migrationDir' | 'pool'>, DrizzleAdapter {
|
140
33
|
beginTransaction: (options?: PgTransactionConfig) => Promise<null | number | string>;
|
@@ -153,6 +46,7 @@ declare module 'payload' {
|
|
153
46
|
table: PgTableFn;
|
154
47
|
} | PgSchema;
|
155
48
|
pool: Pool;
|
49
|
+
poolOptions: Args['pool'];
|
156
50
|
prodMigrations?: {
|
157
51
|
down: (args: MigrateDownArgs) => Promise<void>;
|
158
52
|
name: string;
|
@@ -168,5 +62,4 @@ declare module 'payload' {
|
|
168
62
|
versionsSuffix?: string;
|
169
63
|
}
|
170
64
|
}
|
171
|
-
export {};
|
172
65
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,WAAW,EACX,eAAe,EACf,aAAa,EACb,UAAU,EACX,MAAM,8BAA8B,CAAA;AACrC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AACnF,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAE1C,MAAM,MAAM,IAAI,GAAG;IACjB,MAAM,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAA;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,MAAM,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAA;IAChC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,IAAI,EAAE,UAAU,CAAA;IAChB,cAAc,CAAC,EAAE;QACf,IAAI,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;QAC9C,IAAI,EAAE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AAM,CAAC,CAAA;QACzB,cAAc,CAAC,EAAE;YACf,IAAI,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;YAC9C,IAAI,EAAE,MAAM,CAAA;YACZ,EAAE,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;SAC3C,EAAE,CAAA;QACH,IAAI,EAAE,OAAO,CAAA;QACb,kBAAkB,EAAE,MAAM,IAAI,CAAA;QAC9B,mBAAmB,CAAC,EAAE,MAAM,CAAA;QAC5B,mBAAmB,EAAE,MAAM,IAAI,CAAA;QAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAC/B,UAAU,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;QAC/B,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACjC,cAAc,CAAC,EAAE,MAAM,CAAA;KACxB;CACF"}
|
package/dist/types.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n BasePostgresAdapter,\n GenericEnum,\n MigrateDownArgs,\n MigrateUpArgs,\n PostgresDB,\n} from '@payloadcms/drizzle/postgres'\nimport type { DrizzleAdapter } from '@payloadcms/drizzle/types'\nimport type { DrizzleConfig } from 'drizzle-orm'\nimport type { PgSchema, PgTableFn, PgTransactionConfig } from 'drizzle-orm/pg-core'\nimport type { Pool, PoolConfig } from 'pg'\n\nexport type Args = {\n idType?: 'serial' | 'uuid'\n localesSuffix?: string\n logger?: DrizzleConfig['logger']\n migrationDir?: string\n pool: PoolConfig\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\n push?: boolean\n relationshipsSuffix?: string\n /**\n * The schema name to use for the database\n * @experimental This only works when there are not other tables or enums of the same name in the database under a different schema. Awaiting fix from Drizzle.\n */\n schemaName?: string\n transactionOptions?: PgTransactionConfig | false\n versionsSuffix?: string\n}\n\nexport type PostgresAdapter = {\n pool: Pool\n poolOptions: PoolConfig\n} & BasePostgresAdapter\n\ndeclare module 'payload' {\n export interface DatabaseAdapter\n extends Omit<Args, 'idType' | 'logger' | 'migrationDir' | 'pool'>,\n DrizzleAdapter {\n beginTransaction: (options?: PgTransactionConfig) => Promise<null | number | string>\n drizzle: PostgresDB\n enums: Record<string, GenericEnum>\n /**\n * An object keyed on each table, with a key value pair where the constraint name is the key, followed by the dot-notation field name\n * Used for returning properly formed errors from unique fields\n */\n fieldConstraints: Record<string, Record<string, string>>\n idType: Args['idType']\n initializing: Promise<void>\n localesSuffix?: string\n logger: DrizzleConfig['logger']\n pgSchema?: { table: PgTableFn } | PgSchema\n pool: Pool\n poolOptions: Args['pool']\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\n push: boolean\n rejectInitializing: () => void\n relationshipsSuffix?: string\n resolveInitializing: () => void\n schema: Record<string, unknown>\n schemaName?: Args['schemaName']\n tableNameMap: Map<string, string>\n versionsSuffix?: string\n }\n}\n"],"names":[],"mappings":"AAkCA,WAGuB"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@payloadcms/db-postgres",
|
3
|
-
"version": "3.0.0-canary.
|
3
|
+
"version": "3.0.0-canary.ff8c8fd",
|
4
4
|
"description": "The officially supported Postgres database adapter for Payload",
|
5
5
|
"homepage": "https://payloadcms.com",
|
6
6
|
"repository": {
|
@@ -42,19 +42,18 @@
|
|
42
42
|
"prompts": "2.4.2",
|
43
43
|
"to-snake-case": "1.0.0",
|
44
44
|
"uuid": "10.0.0",
|
45
|
-
"@payloadcms/drizzle": "3.0.0-canary.
|
45
|
+
"@payloadcms/drizzle": "3.0.0-canary.ff8c8fd"
|
46
46
|
},
|
47
47
|
"devDependencies": {
|
48
48
|
"@hyrious/esbuild-plugin-commonjs": "^0.2.4",
|
49
49
|
"@types/pg": "8.10.2",
|
50
50
|
"@types/to-snake-case": "1.0.0",
|
51
|
-
"
|
52
|
-
"
|
53
|
-
"payload": "3.0.0-canary.
|
54
|
-
"@payloadcms/eslint-config": "3.0.0-beta.59"
|
51
|
+
"esbuild": "0.23.1",
|
52
|
+
"@payloadcms/eslint-config": "3.0.0-beta.59",
|
53
|
+
"payload": "3.0.0-canary.ff8c8fd"
|
55
54
|
},
|
56
55
|
"peerDependencies": {
|
57
|
-
"payload": "3.0.0-canary.
|
56
|
+
"payload": "3.0.0-canary.ff8c8fd"
|
58
57
|
},
|
59
58
|
"scripts": {
|
60
59
|
"build": "rimraf .dist && rimraf tsconfig.tsbuildinfo && pnpm build:types && pnpm build:swc && pnpm build:esbuild && pnpm renamePredefinedMigrations",
|
@@ -62,6 +61,6 @@
|
|
62
61
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
63
62
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
64
63
|
"clean": "rimraf {dist,*.tsbuildinfo}",
|
65
|
-
"renamePredefinedMigrations": "
|
64
|
+
"renamePredefinedMigrations": "node --no-deprecation --import @swc-node/register/esm-register ./scripts/renamePredefinedMigrations.ts"
|
66
65
|
}
|
67
66
|
}
|
@@ -1,11 +0,0 @@
|
|
1
|
-
import type { TransactionPg } from '@payloadcms/drizzle/types';
|
2
|
-
import type { DrizzleConfig } from 'drizzle-orm';
|
3
|
-
import type { NodePgClient } from 'drizzle-orm/node-postgres';
|
4
|
-
import type { PostgresDB } from '../types.js';
|
5
|
-
export declare const nodePostgres: (args: {
|
6
|
-
client: NodePgClient;
|
7
|
-
config?: Pick<DrizzleConfig, "logger" | "schema">;
|
8
|
-
}) => {
|
9
|
-
drizzle: PostgresDB | TransactionPg;
|
10
|
-
};
|
11
|
-
//# sourceMappingURL=nodePostgres.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"nodePostgres.d.ts","sourceRoot":"","sources":["../../src/connectionHelpers/nodePostgres.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAI7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,eAAO,MAAM,YAAY,SAAU;IACjC,MAAM,EAAE,YAAY,CAAA;IACpB,MAAM,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ,GAAG,QAAQ,CAAC,CAAA;CAClD,KAAG;IAAE,OAAO,EAAE,UAAU,GAAG,aAAa,CAAA;CAExC,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/connectionHelpers/nodePostgres.ts"],"sourcesContent":["import type { TransactionPg } from '@payloadcms/drizzle/types'\nimport type { DrizzleConfig } from 'drizzle-orm'\nimport type { NodePgClient } from 'drizzle-orm/node-postgres'\n\nimport { drizzle } from 'drizzle-orm/node-postgres'\n\nimport type { PostgresDB } from '../types.js'\n\nexport const nodePostgres = (args: {\n client: NodePgClient\n config?: Pick<DrizzleConfig, 'logger' | 'schema'>\n}): { drizzle: PostgresDB | TransactionPg } => {\n return drizzle(args.client, args.config) as unknown as { drizzle: PostgresDB | TransactionPg }\n}\n"],"names":["drizzle","nodePostgres","args","client","config"],"mappings":"AAIA,SAASA,OAAO,QAAQ,4BAA2B;AAInD,OAAO,MAAMC,eAAe,CAACC;IAI3B,OAAOF,QAAQE,KAAKC,MAAM,EAAED,KAAKE,MAAM;AACzC,EAAC"}
|
package/dist/countDistinct.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"countDistinct.d.ts","sourceRoot":"","sources":["../src/countDistinct.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAmB,MAAM,YAAY,CAAA;AAEhE,eAAO,MAAM,aAAa,EAAE,aAyB3B,CAAA"}
|
package/dist/countDistinct.js
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
import { chainMethods } from '@payloadcms/drizzle';
|
2
|
-
import { sql } from 'drizzle-orm';
|
3
|
-
export const countDistinct = async function countDistinct({ db, joins, tableName, where }) {
|
4
|
-
const chainedMethods = [];
|
5
|
-
joins.forEach(({ condition, table })=>{
|
6
|
-
chainedMethods.push({
|
7
|
-
args: [
|
8
|
-
table,
|
9
|
-
condition
|
10
|
-
],
|
11
|
-
method: 'leftJoin'
|
12
|
-
});
|
13
|
-
});
|
14
|
-
const countResult = await chainMethods({
|
15
|
-
methods: chainedMethods,
|
16
|
-
query: db.select({
|
17
|
-
count: sql`count
|
18
|
-
(DISTINCT ${this.tables[tableName].id})`
|
19
|
-
}).from(this.tables[tableName]).where(where)
|
20
|
-
});
|
21
|
-
return Number(countResult[0].count);
|
22
|
-
};
|
23
|
-
|
24
|
-
//# sourceMappingURL=countDistinct.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../src/countDistinct.ts"],"sourcesContent":["import type { ChainedMethods, TransactionPg } from '@payloadcms/drizzle/types'\n\nimport { chainMethods } from '@payloadcms/drizzle'\nimport { sql } from 'drizzle-orm'\n\nimport type { CountDistinct, PostgresAdapter } from './types.js'\n\nexport const countDistinct: CountDistinct = async function countDistinct(\n this: PostgresAdapter,\n { db, joins, tableName, where },\n) {\n const chainedMethods: ChainedMethods = []\n\n joins.forEach(({ condition, table }) => {\n chainedMethods.push({\n args: [table, condition],\n method: 'leftJoin',\n })\n })\n\n const countResult = await chainMethods({\n methods: chainedMethods,\n query: (db as TransactionPg)\n .select({\n count: sql<string>`count\n (DISTINCT ${this.tables[tableName].id})`,\n })\n .from(this.tables[tableName])\n .where(where),\n })\n\n return Number(countResult[0].count)\n}\n"],"names":["chainMethods","sql","countDistinct","db","joins","tableName","where","chainedMethods","forEach","condition","table","push","args","method","countResult","methods","query","select","count","tables","id","from","Number"],"mappings":"AAEA,SAASA,YAAY,QAAQ,sBAAqB;AAClD,SAASC,GAAG,QAAQ,cAAa;AAIjC,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,KAAK,EAAEC,SAAS,EAAEC,KAAK,EAAE;IAE/B,MAAMC,iBAAiC,EAAE;IAEzCH,MAAMI,OAAO,CAAC,CAAC,EAAEC,SAAS,EAAEC,KAAK,EAAE;QACjCH,eAAeI,IAAI,CAAC;YAClBC,MAAM;gBAACF;gBAAOD;aAAU;YACxBI,QAAQ;QACV;IACF;IAEA,MAAMC,cAAc,MAAMd,aAAa;QACrCe,SAASR;QACTS,OAAO,AAACb,GACLc,MAAM,CAAC;YACNC,OAAOjB,GAAW,CAAC;sBACL,EAAE,IAAI,CAACkB,MAAM,CAACd,UAAU,CAACe,EAAE,CAAC,CAAC,CAAC;QAC9C,GACCC,IAAI,CAAC,IAAI,CAACF,MAAM,CAACd,UAAU,EAC3BC,KAAK,CAACA;IACX;IAEA,OAAOgB,OAAOR,WAAW,CAAC,EAAE,CAACI,KAAK;AACpC,EAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"convertPathToJSONTraversal.d.ts","sourceRoot":"","sources":["../../src/createJSONQuery/convertPathToJSONTraversal.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,0BAA0B,qBAAsB,MAAM,EAAE,WAUpE,CAAA"}
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import { formatJSONPathSegment } from './formatJSONPathSegment.js';
|
2
|
-
export const convertPathToJSONTraversal = (incomingSegments)=>{
|
3
|
-
const segments = [
|
4
|
-
...incomingSegments
|
5
|
-
];
|
6
|
-
segments.shift();
|
7
|
-
return segments.reduce((res, segment, i)=>{
|
8
|
-
const formattedSegment = formatJSONPathSegment(segment);
|
9
|
-
if (i + 1 === segments.length) return `${res}->>${formattedSegment}`;
|
10
|
-
return `${res}->${formattedSegment}`;
|
11
|
-
}, '');
|
12
|
-
};
|
13
|
-
|
14
|
-
//# sourceMappingURL=convertPathToJSONTraversal.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/createJSONQuery/convertPathToJSONTraversal.ts"],"sourcesContent":["import { formatJSONPathSegment } from './formatJSONPathSegment.js'\n\nexport const convertPathToJSONTraversal = (incomingSegments: string[]) => {\n const segments = [...incomingSegments]\n segments.shift()\n\n return segments.reduce((res, segment, i) => {\n const formattedSegment = formatJSONPathSegment(segment)\n\n if (i + 1 === segments.length) return `${res}->>${formattedSegment}`\n return `${res}->${formattedSegment}`\n }, '')\n}\n"],"names":["formatJSONPathSegment","convertPathToJSONTraversal","incomingSegments","segments","shift","reduce","res","segment","i","formattedSegment","length"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,6BAA4B;AAElE,OAAO,MAAMC,6BAA6B,CAACC;IACzC,MAAMC,WAAW;WAAID;KAAiB;IACtCC,SAASC,KAAK;IAEd,OAAOD,SAASE,MAAM,CAAC,CAACC,KAAKC,SAASC;QACpC,MAAMC,mBAAmBT,sBAAsBO;QAE/C,IAAIC,IAAI,MAAML,SAASO,MAAM,EAAE,OAAO,CAAC,EAAEJ,IAAI,GAAG,EAAEG,iBAAiB,CAAC;QACpE,OAAO,CAAC,EAAEH,IAAI,EAAE,EAAEG,iBAAiB,CAAC;IACtC,GAAG;AACL,EAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"formatJSONPathSegment.d.ts","sourceRoot":"","sources":["../../src/createJSONQuery/formatJSONPathSegment.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,YAAa,MAAM,WAEpD,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/createJSONQuery/formatJSONPathSegment.ts"],"sourcesContent":["export const formatJSONPathSegment = (segment: string) => {\n return Number.isNaN(parseInt(segment)) ? `'${segment}'` : segment\n}\n"],"names":["formatJSONPathSegment","segment","Number","isNaN","parseInt"],"mappings":"AAAA,OAAO,MAAMA,wBAAwB,CAACC;IACpC,OAAOC,OAAOC,KAAK,CAACC,SAASH,YAAY,CAAC,CAAC,EAAEA,QAAQ,CAAC,CAAC,GAAGA;AAC5D,EAAC"}
|
@@ -1,10 +0,0 @@
|
|
1
|
-
type Args = {
|
2
|
-
operator: string;
|
3
|
-
pathSegments: string[];
|
4
|
-
treatAsArray?: string[];
|
5
|
-
treatRootAsArray?: boolean;
|
6
|
-
value: unknown;
|
7
|
-
};
|
8
|
-
export declare const createJSONQuery: ({ operator, pathSegments, treatAsArray, treatRootAsArray, value, }: Args) => string;
|
9
|
-
export {};
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/createJSONQuery/index.ts"],"names":[],"mappings":"AAmDA,KAAK,IAAI,GAAG;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAED,eAAO,MAAM,eAAe,uEAMzB,IAAI,KAAG,MAqBT,CAAA"}
|