@payloadcms/db-sqlite 3.0.0-canary.d894ac7 → 3.0.0-canary.e198dc5
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/connect.d.ts.map +1 -1
- package/dist/connect.js +10 -3
- package/dist/connect.js.map +1 -1
- package/dist/countDistinct.d.ts.map +1 -1
- package/dist/countDistinct.js +3 -3
- package/dist/countDistinct.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +24 -4
- package/dist/init.js.map +1 -1
- package/dist/schema/build.d.ts +13 -3
- package/dist/schema/build.d.ts.map +1 -1
- package/dist/schema/build.js +18 -8
- package/dist/schema/build.js.map +1 -1
- package/dist/schema/createIndex.d.ts.map +1 -1
- package/dist/schema/createIndex.js +3 -1
- package/dist/schema/createIndex.js.map +1 -1
- package/dist/schema/traverseFields.d.ts +9 -3
- package/dist/schema/traverseFields.d.ts.map +1 -1
- package/dist/schema/traverseFields.js +191 -62
- package/dist/schema/traverseFields.js.map +1 -1
- package/dist/schema/withDefault.d.ts.map +1 -1
- package/dist/schema/withDefault.js +3 -1
- package/dist/schema/withDefault.js.map +1 -1
- package/dist/types.d.ts +30 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +11 -9
package/dist/connect.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAQtC,eAAO,MAAM,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAQtC,eAAO,MAAM,OAAO,EAAE,OAoDrB,CAAA"}
|
package/dist/connect.js
CHANGED
|
@@ -28,15 +28,22 @@ export const connect = async function connect(options = {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
} catch (err) {
|
|
31
|
-
this.payload.logger.error(
|
|
32
|
-
|
|
31
|
+
this.payload.logger.error({
|
|
32
|
+
err,
|
|
33
|
+
msg: `Error: cannot connect to SQLite: ${err.message}`
|
|
34
|
+
});
|
|
35
|
+
if (typeof this.rejectInitializing === 'function') {
|
|
36
|
+
this.rejectInitializing();
|
|
37
|
+
}
|
|
33
38
|
process.exit(1);
|
|
34
39
|
}
|
|
35
40
|
// Only push schema if not in production
|
|
36
41
|
if (process.env.NODE_ENV !== 'production' && process.env.PAYLOAD_MIGRATING !== 'true' && this.push !== false) {
|
|
37
42
|
await pushDevSchema(this);
|
|
38
43
|
}
|
|
39
|
-
if (typeof this.resolveInitializing === 'function')
|
|
44
|
+
if (typeof this.resolveInitializing === 'function') {
|
|
45
|
+
this.resolveInitializing();
|
|
46
|
+
}
|
|
40
47
|
if (process.env.NODE_ENV === 'production' && this.prodMigrations) {
|
|
41
48
|
await this.migrate({
|
|
42
49
|
migrations: this.prodMigrations
|
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 { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { Connect } from 'payload'\n\nimport { createClient } from '@libsql/client'\nimport { pushDevSchema } from '@payloadcms/drizzle'\nimport { drizzle } from 'drizzle-orm/libsql'\n\nimport type { SQLiteAdapter } from './types.js'\n\nexport const connect: Connect = async function connect(\n this: SQLiteAdapter,\n options = {\n hotReload: false,\n },\n) {\n const { hotReload } = options\n\n this.schema = {\n ...this.tables,\n ...this.relations,\n }\n\n try {\n if (!this.client) {\n this.client = createClient(this.clientConfig)\n }\n\n const logger = this.logger || false\n this.drizzle = drizzle(this.client, { logger, schema: this.schema })
|
|
1
|
+
{"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { DrizzleAdapter } from '@payloadcms/drizzle/types'\nimport type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { Connect } from 'payload'\n\nimport { createClient } from '@libsql/client'\nimport { pushDevSchema } from '@payloadcms/drizzle'\nimport { drizzle } from 'drizzle-orm/libsql'\n\nimport type { SQLiteAdapter } from './types.js'\n\nexport const connect: Connect = async function connect(\n this: SQLiteAdapter,\n options = {\n hotReload: false,\n },\n) {\n const { hotReload } = options\n\n this.schema = {\n ...this.tables,\n ...this.relations,\n }\n\n try {\n if (!this.client) {\n this.client = createClient(this.clientConfig)\n }\n\n const logger = this.logger || false\n this.drizzle = drizzle(this.client, { logger, schema: this.schema })\n\n if (!hotReload) {\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n this.payload.logger.info(`---- DROPPING TABLES ----`)\n await this.dropDatabase({ adapter: this })\n this.payload.logger.info('---- DROPPED TABLES ----')\n }\n }\n } catch (err) {\n this.payload.logger.error({ err, msg: `Error: cannot connect to SQLite: ${err.message}` })\n if (typeof this.rejectInitializing === 'function') {\n this.rejectInitializing()\n }\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') {\n this.resolveInitializing()\n }\n\n if (process.env.NODE_ENV === 'production' && this.prodMigrations) {\n await this.migrate({ migrations: this.prodMigrations })\n }\n}\n"],"names":["createClient","pushDevSchema","drizzle","connect","options","hotReload","schema","tables","relations","client","clientConfig","logger","process","env","PAYLOAD_DROP_DATABASE","payload","info","dropDatabase","adapter","err","error","msg","message","rejectInitializing","exit","NODE_ENV","PAYLOAD_MIGRATING","push","resolveInitializing","prodMigrations","migrate","migrations"],"mappings":"AAIA,SAASA,YAAY,QAA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I,KAAK,OACd;QACA,MAAM1B,cAAc,IAAI;IAC1B;IAEA,IAAI,OAAO,IAAI,CAAC2B,mBAAmB,KAAK,YAAY;QAClD,IAAI,CAACA,mBAAmB;IAC1B;IAEA,IAAIhB,QAAQC,GAAG,CAACY,QAAQ,KAAK,gBAAgB,IAAI,CAACI,cAAc,EAAE;QAChE,MAAM,IAAI,CAACC,OAAO,CAAC;YAAEC,YAAY,IAAI,CAACF,cAAc;QAAC;IACvD;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"countDistinct.d.ts","sourceRoot":"","sources":["../src/countDistinct.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAiB,MAAM,YAAY,CAAA;AAE9D,eAAO,MAAM,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"countDistinct.d.ts","sourceRoot":"","sources":["../src/countDistinct.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAiB,MAAM,YAAY,CAAA;AAE9D,eAAO,MAAM,aAAa,EAAE,aA4B3B,CAAA"}
|
package/dist/countDistinct.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { chainMethods } from '@payloadcms/drizzle';
|
|
2
|
-
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { count, sql } from 'drizzle-orm';
|
|
3
3
|
export const countDistinct = async function countDistinct({ db, joins, tableName, where }) {
|
|
4
4
|
const chainedMethods = [];
|
|
5
5
|
joins.forEach(({ condition, table })=>{
|
|
@@ -14,8 +14,8 @@ export const countDistinct = async function countDistinct({ db, joins, tableName
|
|
|
14
14
|
const countResult = await chainMethods({
|
|
15
15
|
methods: chainedMethods,
|
|
16
16
|
query: db.select({
|
|
17
|
-
count: sql`count
|
|
18
|
-
|
|
17
|
+
count: joins.length > 0 ? sql`count
|
|
18
|
+
(DISTINCT ${this.tables[tableName].id})`.mapWith(Number) : count()
|
|
19
19
|
}).from(this.tables[tableName]).where(where)
|
|
20
20
|
});
|
|
21
21
|
return Number(countResult[0].count);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/countDistinct.ts"],"sourcesContent":["import type { ChainedMethods } from '@payloadcms/drizzle/types'\n\nimport { chainMethods } from '@payloadcms/drizzle'\nimport { sql } from 'drizzle-orm'\n\nimport type { CountDistinct, SQLiteAdapter } from './types.js'\n\nexport const countDistinct: CountDistinct = async function countDistinct(\n this: SQLiteAdapter,\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\n .select({\n count
|
|
1
|
+
{"version":3,"sources":["../src/countDistinct.ts"],"sourcesContent":["import type { ChainedMethods } from '@payloadcms/drizzle/types'\n\nimport { chainMethods } from '@payloadcms/drizzle'\nimport { count, sql } from 'drizzle-orm'\n\nimport type { CountDistinct, SQLiteAdapter } from './types.js'\n\nexport const countDistinct: CountDistinct = async function countDistinct(\n this: SQLiteAdapter,\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\n .select({\n count:\n joins.length > 0\n ? sql`count\n (DISTINCT ${this.tables[tableName].id})`.mapWith(Number)\n : count(),\n })\n .from(this.tables[tableName])\n .where(where),\n })\n\n return Number(countResult[0].count)\n}\n"],"names":["chainMethods","count","sql","countDistinct","db","joins","tableName","where","chainedMethods","forEach","condition","table","push","args","method","countResult","methods","query","select","length","tables","id","mapWith","Number","from"],"mappings":"AAEA,SAASA,YAAY,QAAQ,sBAAqB;AAClD,SAASC,KAAK,EAAEC,GAAG,QAAQ,cAAa;AAIxC,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,MAAMf,aAAa;QACrCgB,SAASR;QACTS,OAAOb,GACJc,MAAM,CAAC;YACNjB,OACEI,MAAMc,MAAM,GAAG,IACXjB,GAAG,CAAC;cACJ,EAAE,IAAI,CAACkB,MAAM,CAACd,UAAU,CAACe,EAAE,CAAC,CAAC,CAAC,CAACC,OAAO,CAACC,UACvCtB;QACR,GACCuB,IAAI,CAAC,IAAI,CAACJ,MAAM,CAACd,UAAU,EAC3BC,KAAK,CAACA;IACX;IAEA,OAAOgB,OAAOR,WAAW,CAAC,EAAE,CAACd,KAAK;AACpC,EAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAW,MAAM,SAAS,CAAA;AAqC1D,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAgBrD,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEhE,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAEjC,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,kBAAkB,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAW,MAAM,SAAS,CAAA;AAqC1D,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAgBrD,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEhE,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAEjC,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,kBAAkB,CAAC,aAAa,CAAC,CAyG3E"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
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
2
|
import { like } from 'drizzle-orm';
|
|
3
|
-
import { createDatabaseAdapter } from 'payload';
|
|
3
|
+
import { createDatabaseAdapter, defaultBeginTransaction } from 'payload';
|
|
4
4
|
import { connect } from './connect.js';
|
|
5
5
|
import { countDistinct } from './countDistinct.js';
|
|
6
6
|
import { convertPathToJSONTraversal } from './createJSONQuery/convertPathToJSONTraversal.js';
|
|
@@ -34,6 +34,8 @@ export function sqliteAdapter(args) {
|
|
|
34
34
|
};
|
|
35
35
|
return createDatabaseAdapter({
|
|
36
36
|
name: 'sqlite',
|
|
37
|
+
afterSchemaInit: args.afterSchemaInit ?? [],
|
|
38
|
+
beforeSchemaInit: args.beforeSchemaInit ?? [],
|
|
37
39
|
client: undefined,
|
|
38
40
|
clientConfig: args.client,
|
|
39
41
|
defaultDrizzleSnapshot,
|
|
@@ -60,7 +62,7 @@ export function sqliteAdapter(args) {
|
|
|
60
62
|
transactionOptions: args.transactionOptions || undefined,
|
|
61
63
|
versionsSuffix: args.versionsSuffix || '_v',
|
|
62
64
|
// DatabaseAdapter
|
|
63
|
-
beginTransaction: args.transactionOptions ? beginTransaction :
|
|
65
|
+
beginTransaction: args.transactionOptions ? beginTransaction : defaultBeginTransaction(),
|
|
64
66
|
commitTransaction,
|
|
65
67
|
connect,
|
|
66
68
|
convertPathToJSONTraversal,
|
|
@@ -94,6 +96,7 @@ export function sqliteAdapter(args) {
|
|
|
94
96
|
migrateReset,
|
|
95
97
|
migrateStatus,
|
|
96
98
|
migrationDir,
|
|
99
|
+
packageName: '@payloadcms/db-sqlite',
|
|
97
100
|
payload,
|
|
98
101
|
queryDrafts,
|
|
99
102
|
rejectInitializing,
|
|
@@ -103,7 +106,8 @@ export function sqliteAdapter(args) {
|
|
|
103
106
|
updateGlobal,
|
|
104
107
|
updateGlobalVersion,
|
|
105
108
|
updateOne,
|
|
106
|
-
updateVersion
|
|
109
|
+
updateVersion,
|
|
110
|
+
upsert: updateOne
|
|
107
111
|
});
|
|
108
112
|
}
|
|
109
113
|
return {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Operators } from '@payloadcms/drizzle'\nimport 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 { like } from 'drizzle-orm'\nimport { createDatabaseAdapter } from 'payload'\n\nimport type { Args, SQLiteAdapter } from './types.js'\n\nimport { connect } from './connect.js'\nimport { countDistinct } from './countDistinct.js'\nimport { convertPathToJSONTraversal } from './createJSONQuery/convertPathToJSONTraversal.js'\nimport { createJSONQuery } from './createJSONQuery/index.js'\nimport { createMigration } from './createMigration.js'\nimport { defaultDrizzleSnapshot } from './defaultSnapshot.js'\nimport { deleteWhere } from './deleteWhere.js'\nimport { dropDatabase } from './dropDatabase.js'\nimport { execute } from './execute.js'\nimport { getMigrationTemplate } from './getMigrationTemplate.js'\nimport { init } from './init.js'\nimport { insert } from './insert.js'\nimport { requireDrizzleKit } from './requireDrizzleKit.js'\n\nexport type { MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nexport { sql } from 'drizzle-orm'\n\nexport function sqliteAdapter(args: Args): DatabaseAdapterObj<SQLiteAdapter> {\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\n const initializing = new Promise<void>((res, rej) => {\n resolveInitializing = res\n rejectInitializing = rej\n })\n\n // sqlite's like operator is case-insensitive, so we overwrite the DrizzleAdapter operators to not use ilike\n const operators = {\n ...operatorMap,\n contains: like,\n like,\n } as unknown as Operators\n\n return createDatabaseAdapter<SQLiteAdapter>({\n name: 'sqlite',\n client: undefined,\n clientConfig: args.client,\n defaultDrizzleSnapshot,\n drizzle: undefined,\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,\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 ? beginTransaction :
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Operators } from '@payloadcms/drizzle'\nimport 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 { like } from 'drizzle-orm'\nimport { createDatabaseAdapter, defaultBeginTransaction } from 'payload'\n\nimport type { Args, SQLiteAdapter } from './types.js'\n\nimport { connect } from './connect.js'\nimport { countDistinct } from './countDistinct.js'\nimport { convertPathToJSONTraversal } from './createJSONQuery/convertPathToJSONTraversal.js'\nimport { createJSONQuery } from './createJSONQuery/index.js'\nimport { createMigration } from './createMigration.js'\nimport { defaultDrizzleSnapshot } from './defaultSnapshot.js'\nimport { deleteWhere } from './deleteWhere.js'\nimport { dropDatabase } from './dropDatabase.js'\nimport { execute } from './execute.js'\nimport { getMigrationTemplate } from './getMigrationTemplate.js'\nimport { init } from './init.js'\nimport { insert } from './insert.js'\nimport { requireDrizzleKit } from './requireDrizzleKit.js'\n\nexport type { MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nexport { sql } from 'drizzle-orm'\n\nexport function sqliteAdapter(args: Args): DatabaseAdapterObj<SQLiteAdapter> {\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\n const initializing = new Promise<void>((res, rej) => {\n resolveInitializing = res\n rejectInitializing = rej\n })\n\n // sqlite's like operator is case-insensitive, so we overwrite the DrizzleAdapter operators to not use ilike\n const operators = {\n ...operatorMap,\n contains: like,\n like,\n } as unknown as Operators\n\n return createDatabaseAdapter<SQLiteAdapter>({\n name: 'sqlite',\n afterSchemaInit: args.afterSchemaInit ?? [],\n beforeSchemaInit: args.beforeSchemaInit ?? [],\n client: undefined,\n clientConfig: args.client,\n defaultDrizzleSnapshot,\n drizzle: undefined,\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,\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 ? beginTransaction : defaultBeginTransaction(),\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-sqlite',\n payload,\n queryDrafts,\n rejectInitializing,\n requireDrizzleKit,\n resolveInitializing,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n upsert: updateOne,\n })\n }\n\n return {\n defaultIDType: payloadIDType,\n init: adapter,\n }\n}\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","like","createDatabaseAdapter","defaultBeginTransaction","connect","countDistinct","convertPathToJSONTraversal","createJSONQuery","createMigration","defaultDrizzleSnapshot","deleteWhere","dropDatabase","execute","getMigrationTemplate","init","insert","requireDrizzleKit","sql","sqliteAdapter","args","postgresIDType","idType","payloadIDType","adapter","payload","migrationDir","resolveInitializing","rejectInitializing","initializing","Promise","res","rej","operators","contains","name","afterSchemaInit","beforeSchemaInit","client","undefined","clientConfig","drizzle","features","json","fieldConstraints","localesSuffix","logger","prodMigrations","push","relations","relationshipsSuffix","schema","schemaName","sessions","tableNameMap","Map","tables","transactionOptions","versionsSuffix","defaultIDType","packageName","upsert"],"mappings":"AAGA,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,EAClBC,gBAAgB,EAChBC,OAAO,EACPC,YAAY,EACZC,OAAO,EACPC,WAAW,EACXC,YAAY,EACZC,cAAc,EACdC,YAAY,EACZC,aAAa,EACbC,WAAW,EACXC,WAAW,EACXC,mBAAmB,EACnBC,YAAY,EACZC,mBAAmB,EACnBC,SAAS,EACTC,aAAa,QACR,sBAAqB;AAC5B,SAASC,IAAI,QAAQ,cAAa;AAClC,SAASC,qBAAqB,EAAEC,uBAAuB,QAAQ,UAAS;AAIxE,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,0BAA0B,QAAQ,kDAAiD;AAC5F,SAASC,eAAe,QAAQ,6BAA4B;AAC5D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,sBAAsB,QAAQ,uBAAsB;AAC7D,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC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AAGrF,mBAAmBgC;YAC/D/B;YACAgC;YACAE;YACAjC;YACAgC;YACA/B;YACAC;YACAC;YACA+B;YACAC;YACA/B;YACAiF,eAAepC;YACf5C;YACAC;YACAC;YACA8B;YACA7B;YACA8B;YACAC;YACA9B;YACAC;YACAC;YACAE;YACAC;YACA2B;YACAC;YACA3B;YACAC;YACAC;YACAC;YACAC;YACAC;YACAgC;YACAkC,aAAa;YACbnC;YACA7B;YACAgC;YACAX;YACAU;YACA9B;YACAC;YACAC;YACAC;YACAC;YACA4D,QAAQ7D;QACV;IACF;IAEA,OAAO;QACL2D,eAAepC;QACfR,MAAMS;IACR;AACF"}
|
package/dist/init.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAA;AAY9D,eAAO,MAAM,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAA;AAY9D,eAAO,MAAM,IAAI,EAAE,IA8HlB,CAAA"}
|
package/dist/init.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { createTableName } from '@payloadcms/drizzle';
|
|
1
|
+
import { createTableName, executeSchemaHooks } from '@payloadcms/drizzle';
|
|
2
2
|
import { uniqueIndex } from 'drizzle-orm/sqlite-core';
|
|
3
3
|
import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload';
|
|
4
4
|
import toSnakeCase from 'to-snake-case';
|
|
5
5
|
import { buildTable } from './schema/build.js';
|
|
6
|
-
export const init = function init() {
|
|
6
|
+
export const init = async function init() {
|
|
7
7
|
let locales;
|
|
8
|
+
await executeSchemaHooks({
|
|
9
|
+
type: 'beforeSchemaInit',
|
|
10
|
+
adapter: this
|
|
11
|
+
});
|
|
8
12
|
if (this.payload.config.localization) {
|
|
9
13
|
locales = this.payload.config.localization.locales.map(({ code })=>code);
|
|
10
14
|
}
|
|
@@ -24,6 +28,7 @@ export const init = function init() {
|
|
|
24
28
|
});
|
|
25
29
|
this.payload.config.collections.forEach((collection)=>{
|
|
26
30
|
const tableName = this.tableNameMap.get(toSnakeCase(collection.slug));
|
|
31
|
+
const config = this.payload.config;
|
|
27
32
|
const baseExtraConfig = {};
|
|
28
33
|
if (collection.upload.filenameCompoundIndex) {
|
|
29
34
|
const indexName = `${tableName}_filename_compound_idx`;
|
|
@@ -34,11 +39,21 @@ export const init = function init() {
|
|
|
34
39
|
return uniqueIndex(indexName).on(colsConstraint[0], ...colsConstraint.slice(1));
|
|
35
40
|
};
|
|
36
41
|
}
|
|
42
|
+
if (collection.upload.filenameCompoundIndex) {
|
|
43
|
+
const indexName = `${tableName}_filename_compound_idx`;
|
|
44
|
+
baseExtraConfig.filename_compound_index = (cols)=>{
|
|
45
|
+
const colsConstraint = collection.upload.filenameCompoundIndex.map((f)=>{
|
|
46
|
+
return cols[f];
|
|
47
|
+
});
|
|
48
|
+
return uniqueIndex(indexName).on(colsConstraint[0], ...colsConstraint.slice(1));
|
|
49
|
+
};
|
|
50
|
+
}
|
|
37
51
|
buildTable({
|
|
38
52
|
adapter: this,
|
|
39
53
|
disableNotNull: !!collection?.versions?.drafts,
|
|
40
54
|
disableUnique: false,
|
|
41
55
|
fields: collection.fields,
|
|
56
|
+
joins: collection.joins,
|
|
42
57
|
locales,
|
|
43
58
|
tableName,
|
|
44
59
|
timestamps: collection.timestamps,
|
|
@@ -46,7 +61,7 @@ export const init = function init() {
|
|
|
46
61
|
});
|
|
47
62
|
if (collection.versions) {
|
|
48
63
|
const versionsTableName = this.tableNameMap.get(`_${toSnakeCase(collection.slug)}${this.versionsSuffix}`);
|
|
49
|
-
const versionFields = buildVersionCollectionFields(collection);
|
|
64
|
+
const versionFields = buildVersionCollectionFields(config, collection);
|
|
50
65
|
buildTable({
|
|
51
66
|
adapter: this,
|
|
52
67
|
disableNotNull: !!collection.versions?.drafts,
|
|
@@ -81,7 +96,8 @@ export const init = function init() {
|
|
|
81
96
|
versions: true,
|
|
82
97
|
versionsCustomName: true
|
|
83
98
|
});
|
|
84
|
-
const
|
|
99
|
+
const config = this.payload.config;
|
|
100
|
+
const versionFields = buildVersionGlobalFields(config, global);
|
|
85
101
|
buildTable({
|
|
86
102
|
adapter: this,
|
|
87
103
|
disableNotNull: !!global.versions?.drafts,
|
|
@@ -94,6 +110,10 @@ export const init = function init() {
|
|
|
94
110
|
});
|
|
95
111
|
}
|
|
96
112
|
});
|
|
113
|
+
await executeSchemaHooks({
|
|
114
|
+
type: 'afterSchemaInit',
|
|
115
|
+
adapter: this
|
|
116
|
+
});
|
|
97
117
|
};
|
|
98
118
|
|
|
99
119
|
//# sourceMappingURL=init.js.map
|
package/dist/init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/init.ts"],"sourcesContent":["import type { DrizzleAdapter } from '@payloadcms/drizzle/types'\nimport type { Init, SanitizedCollectionConfig } from 'payload'\n\nimport { createTableName } from '@payloadcms/drizzle'\nimport { uniqueIndex } from 'drizzle-orm/sqlite-core'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { BaseExtraConfig } from './schema/build.js'\nimport type { SQLiteAdapter } from './types.js'\n\nimport { buildTable } from './schema/build.js'\n\nexport const init: Init = function init(this: SQLiteAdapter) {\n let locales: [string, ...string[]] | undefined\n if (this.payload.config.localization) {\n locales = this.payload.config.localization.locales.map(({ code }) => code) as [\n string,\n ...string[],\n ]\n }\n\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n createTableName({\n adapter: this as unknown as DrizzleAdapter,\n config: collection,\n })\n\n if (collection.versions) {\n createTableName({\n adapter: this as unknown as DrizzleAdapter,\n config: collection,\n versions: true,\n versionsCustomName: true,\n })\n }\n })\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n\n const baseExtraConfig: BaseExtraConfig = {}\n\n if (collection.upload.filenameCompoundIndex) {\n const indexName = `${tableName}_filename_compound_idx`\n\n baseExtraConfig.filename_compound_index = (cols) => {\n const colsConstraint = collection.upload.filenameCompoundIndex.map((f) => {\n return cols[f]\n })\n return uniqueIndex(indexName).on(colsConstraint[0], ...colsConstraint.slice(1))\n }\n }\n\n buildTable({\n adapter: this,\n disableNotNull: !!collection?.versions?.drafts,\n disableUnique: false,\n fields: collection.fields,\n locales,\n tableName,\n timestamps: collection.timestamps,\n versions: false,\n })\n\n if (collection.versions) {\n const versionsTableName = this.tableNameMap.get(\n `_${toSnakeCase(collection.slug)}${this.versionsSuffix}`,\n )\n const versionFields = buildVersionCollectionFields(collection)\n\n buildTable({\n adapter: this,\n disableNotNull: !!collection.versions?.drafts,\n disableUnique: true,\n fields: versionFields,\n locales,\n tableName: versionsTableName,\n timestamps: true,\n versions: true,\n })\n }\n })\n\n this.payload.config.globals.forEach((global) => {\n const tableName = createTableName({\n adapter: this as unknown as DrizzleAdapter,\n config: global,\n })\n\n buildTable({\n adapter: this,\n disableNotNull: !!global?.versions?.drafts,\n disableUnique: false,\n fields: global.fields,\n locales,\n tableName,\n timestamps: false,\n versions: false,\n })\n\n if (global.versions) {\n const versionsTableName = createTableName({\n adapter: this as unknown as DrizzleAdapter,\n config: global,\n versions: true,\n versionsCustomName: true,\n })\n const versionFields = buildVersionGlobalFields(global)\n\n buildTable({\n adapter: this,\n disableNotNull: !!global.versions?.drafts,\n disableUnique: true,\n fields: versionFields,\n locales,\n tableName: versionsTableName,\n timestamps: true,\n versions: true,\n })\n }\n })\n}\n"],"names":["createTableName","uniqueIndex","buildVersionCollectionFields","buildVersionGlobalFields","toSnakeCase","buildTable","init","locales","payload","config","localization","map","code","collections","forEach","collection","
|
|
1
|
+
{"version":3,"sources":["../src/init.ts"],"sourcesContent":["import type { DrizzleAdapter } from '@payloadcms/drizzle/types'\nimport type { Init, SanitizedCollectionConfig } from 'payload'\n\nimport { createTableName, executeSchemaHooks } from '@payloadcms/drizzle'\nimport { uniqueIndex } from 'drizzle-orm/sqlite-core'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { BaseExtraConfig } from './schema/build.js'\nimport type { SQLiteAdapter } from './types.js'\n\nimport { buildTable } from './schema/build.js'\n\nexport const init: Init = async function init(this: SQLiteAdapter) {\n let locales: [string, ...string[]] | undefined\n await executeSchemaHooks({ type: 'beforeSchemaInit', adapter: this })\n\n if (this.payload.config.localization) {\n locales = this.payload.config.localization.locales.map(({ code }) => code) as [\n string,\n ...string[],\n ]\n }\n\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n createTableName({\n adapter: this as unknown as DrizzleAdapter,\n config: collection,\n })\n\n if (collection.versions) {\n createTableName({\n adapter: this as unknown as DrizzleAdapter,\n config: collection,\n versions: true,\n versionsCustomName: true,\n })\n }\n })\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n const config = this.payload.config\n\n const baseExtraConfig: BaseExtraConfig = {}\n\n if (collection.upload.filenameCompoundIndex) {\n const indexName = `${tableName}_filename_compound_idx`\n\n baseExtraConfig.filename_compound_index = (cols) => {\n const colsConstraint = collection.upload.filenameCompoundIndex.map((f) => {\n return cols[f]\n })\n return uniqueIndex(indexName).on(colsConstraint[0], ...colsConstraint.slice(1))\n }\n }\n\n if (collection.upload.filenameCompoundIndex) {\n const indexName = `${tableName}_filename_compound_idx`\n\n baseExtraConfig.filename_compound_index = (cols) => {\n const colsConstraint = collection.upload.filenameCompoundIndex.map((f) => {\n return cols[f]\n })\n return uniqueIndex(indexName).on(colsConstraint[0], ...colsConstraint.slice(1))\n }\n }\n\n buildTable({\n adapter: this,\n disableNotNull: !!collection?.versions?.drafts,\n disableUnique: false,\n fields: collection.fields,\n joins: collection.joins,\n locales,\n tableName,\n timestamps: collection.timestamps,\n versions: false,\n })\n\n if (collection.versions) {\n const versionsTableName = this.tableNameMap.get(\n `_${toSnakeCase(collection.slug)}${this.versionsSuffix}`,\n )\n const versionFields = buildVersionCollectionFields(config, collection)\n\n buildTable({\n adapter: this,\n disableNotNull: !!collection.versions?.drafts,\n disableUnique: true,\n fields: versionFields,\n locales,\n tableName: versionsTableName,\n timestamps: true,\n versions: true,\n })\n }\n })\n\n this.payload.config.globals.forEach((global) => {\n const tableName = createTableName({\n adapter: this as unknown as DrizzleAdapter,\n config: global,\n })\n\n buildTable({\n adapter: this,\n disableNotNull: !!global?.versions?.drafts,\n disableUnique: false,\n fields: global.fields,\n locales,\n tableName,\n timestamps: false,\n versions: false,\n })\n\n if (global.versions) {\n const versionsTableName = createTableName({\n adapter: this as unknown as DrizzleAdapter,\n config: global,\n versions: true,\n versionsCustomName: true,\n })\n const config = this.payload.config\n const versionFields = buildVersionGlobalFields(config, global)\n\n buildTable({\n adapter: this,\n disableNotNull: !!global.versions?.drafts,\n disableUnique: true,\n fields: versionFields,\n locales,\n tableName: versionsTableName,\n timestamps: true,\n versions: true,\n })\n }\n })\n\n await executeSchemaHooks({ type: 'afterSchemaInit', adapter: this })\n}\n"],"names":["createTableName","executeSchemaHooks","uniqueIndex","buildVersionCollectionFields","buildVersionGlobalFields","toSnakeCase","buildTable","init","locales","type","adapter","payload","config","localization","map","code","collections","forEach","collection","versions","versionsCustomName","tableName","tableNameMap","get","slug","baseExtraConfig","upload","filenameCompoundIndex","indexName","filename_compound_index","cols","colsConstraint","f","on","slice","disableNotNull","drafts","disableUnique","fields","joins","timestamps","versionsTableName","versionsSuffix","versionFields","globals","global"],"mappings":"AAGA,SAASA,eAAe,EAAEC,kBAAkB,QAAQ,sBAAqB;AACzE,SAASC,WAAW,QAAQ,0BAAyB;AACrD,SAASC,4BAA4B,EAAEC,wBAAwB,QAAQ,UAA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YAAY;YACZrB,UAAU;QACZ;QAEA,IAAI0B,OAAO1B,QAAQ,EAAE;YACnB,MAAMsB,oBAAoBzC,gBAAgB;gBACxCU,SAAS,IAAI;gBACbE,QAAQiC;gBACR1B,UAAU;gBACVC,oBAAoB;YACtB;YACA,MAAMR,SAAS,IAAI,CAACD,OAAO,CAACC,MAAM;YAClC,MAAM+B,gBAAgBvC,yBAAyBQ,QAAQiC;YAEvDvC,WAAW;gBACTI,SAAS,IAAI;gBACbyB,gBAAgB,CAAC,CAACU,OAAO1B,QAAQ,EAAEiB;gBACnCC,eAAe;gBACfC,QAAQK;gBACRnC;gBACAa,WAAWoB;gBACXD,YAAY;gBACZrB,UAAU;YACZ;QACF;IACF;IAEA,MAAMlB,mBAAmB;QAAEQ,MAAM;QAAmBC,SAAS,IAAI;IAAC;AACpE,EAAC"}
|
package/dist/schema/build.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { AnySQLiteColumn, ForeignKeyBuilder, IndexBuilder, SQLiteColumnBuilder, UniqueConstraintBuilder } from 'drizzle-orm/sqlite-core';
|
|
2
|
-
import type { Field } from 'payload';
|
|
2
|
+
import type { Field, SanitizedJoins } from 'payload';
|
|
3
3
|
import type { IDType, SQLiteAdapter } from '../types.js';
|
|
4
4
|
export type BaseExtraConfig = Record<string, (cols: {
|
|
5
5
|
[x: string]: AnySQLiteColumn;
|
|
6
6
|
}) => ForeignKeyBuilder | IndexBuilder | UniqueConstraintBuilder>;
|
|
7
7
|
export type RelationMap = Map<string, {
|
|
8
8
|
localized: boolean;
|
|
9
|
+
relationName?: string;
|
|
9
10
|
target: string;
|
|
10
11
|
type: 'many' | 'one';
|
|
11
12
|
}>;
|
|
@@ -22,20 +23,29 @@ type Args = {
|
|
|
22
23
|
disableNotNull: boolean;
|
|
23
24
|
disableUnique: boolean;
|
|
24
25
|
fields: Field[];
|
|
26
|
+
joins?: SanitizedJoins;
|
|
25
27
|
locales?: [string, ...string[]];
|
|
26
|
-
rootRelationsToBuild?: RelationMap;
|
|
27
28
|
rootRelationships?: Set<string>;
|
|
29
|
+
rootRelationsToBuild?: RelationMap;
|
|
28
30
|
rootTableIDColType?: IDType;
|
|
29
31
|
rootTableName?: string;
|
|
30
32
|
tableName: string;
|
|
31
33
|
timestamps?: boolean;
|
|
32
34
|
versions: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Tracks whether or not this table is built
|
|
37
|
+
* from the result of a localized array or block field at some point
|
|
38
|
+
*/
|
|
39
|
+
withinLocalizedArrayOrBlock?: boolean;
|
|
33
40
|
};
|
|
34
41
|
type Result = {
|
|
42
|
+
hasLocalizedManyNumberField: boolean;
|
|
43
|
+
hasLocalizedManyTextField: boolean;
|
|
44
|
+
hasLocalizedRelationshipField: boolean;
|
|
35
45
|
hasManyNumberField: 'index' | boolean;
|
|
36
46
|
hasManyTextField: 'index' | boolean;
|
|
37
47
|
relationsToBuild: RelationMap;
|
|
38
48
|
};
|
|
39
|
-
export declare const buildTable: ({ adapter, baseColumns, baseExtraConfig, disableNotNull, disableUnique, fields,
|
|
49
|
+
export declare const buildTable: ({ adapter, baseColumns, baseExtraConfig, disableNotNull, disableUnique, fields, joins, locales, rootRelationships, rootRelationsToBuild, rootTableIDColType, rootTableName: incomingRootTableName, tableName, timestamps, versions, withinLocalizedArrayOrBlock, }: Args) => Result;
|
|
40
50
|
export {};
|
|
41
51
|
//# sourceMappingURL=build.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/schema/build.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EAEnB,uBAAuB,EACxB,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/schema/build.ts"],"names":[],"mappings":"AACA,OA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AAM,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;IACjB;;;OAGG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAA;CACtC,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,2BAA2B,EAAE,OAAO,CAAA;IACpC,yBAAyB,EAAE,OAAO,CAAA;IAClC,6BAA6B,EAAE,OAAO,CAAA;IACtC,kBAAkB,EAAE,OAAO,GAAG,OAAO,CAAA;IACrC,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAA;IACnC,gBAAgB,EAAE,WAAW,CAAA;CAC9B,CAAA;AAED,eAAO,MAAM,UAAU,uQAiBpB,IAAI,KAAG,MA2ZT,CAAA"}
|
package/dist/schema/build.js
CHANGED
|
@@ -5,7 +5,7 @@ import toSnakeCase from 'to-snake-case';
|
|
|
5
5
|
import { getIDColumn } from './getIDColumn.js';
|
|
6
6
|
import { setColumnID } from './setColumnID.js';
|
|
7
7
|
import { traverseFields } from './traverseFields.js';
|
|
8
|
-
export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, disableNotNull, disableUnique = false, fields,
|
|
8
|
+
export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, disableNotNull, disableUnique = false, fields, joins, locales, rootRelationships, rootRelationsToBuild, rootTableIDColType, rootTableName: incomingRootTableName, tableName, timestamps, versions, withinLocalizedArrayOrBlock })=>{
|
|
9
9
|
const isRoot = !incomingRootTableName;
|
|
10
10
|
const rootTableName = incomingRootTableName || tableName;
|
|
11
11
|
const columns = baseColumns;
|
|
@@ -31,25 +31,28 @@ export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, di
|
|
|
31
31
|
disableUnique,
|
|
32
32
|
fields,
|
|
33
33
|
indexes,
|
|
34
|
+
joins,
|
|
34
35
|
locales,
|
|
35
36
|
localesColumns,
|
|
36
37
|
localesIndexes,
|
|
37
38
|
newTableName: tableName,
|
|
38
39
|
parentTableName: tableName,
|
|
39
|
-
relationsToBuild,
|
|
40
40
|
relationships,
|
|
41
|
+
relationsToBuild,
|
|
41
42
|
rootRelationsToBuild: rootRelationsToBuild || relationsToBuild,
|
|
42
43
|
rootTableIDColType: rootTableIDColType || idColType,
|
|
43
44
|
rootTableName,
|
|
44
|
-
versions
|
|
45
|
+
versions,
|
|
46
|
+
withinLocalizedArrayOrBlock
|
|
45
47
|
});
|
|
46
48
|
// split the relationsToBuild by localized and non-localized
|
|
47
49
|
const localizedRelations = new Map();
|
|
48
50
|
const nonLocalizedRelations = new Map();
|
|
49
|
-
relationsToBuild.forEach(({ type, localized, target }, key)=>{
|
|
51
|
+
relationsToBuild.forEach(({ type, localized, relationName, target }, key)=>{
|
|
50
52
|
const map = localized ? localizedRelations : nonLocalizedRelations;
|
|
51
53
|
map.set(key, {
|
|
52
54
|
type,
|
|
55
|
+
relationName,
|
|
53
56
|
target
|
|
54
57
|
});
|
|
55
58
|
});
|
|
@@ -282,8 +285,12 @@ export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, di
|
|
|
282
285
|
});
|
|
283
286
|
let colType = 'integer';
|
|
284
287
|
const relatedCollectionCustomIDType = adapter.payload.collections[relationshipConfig.slug]?.customIDType;
|
|
285
|
-
if (relatedCollectionCustomIDType === 'number')
|
|
286
|
-
|
|
288
|
+
if (relatedCollectionCustomIDType === 'number') {
|
|
289
|
+
colType = 'numeric';
|
|
290
|
+
}
|
|
291
|
+
if (relatedCollectionCustomIDType === 'text') {
|
|
292
|
+
colType = 'text';
|
|
293
|
+
}
|
|
287
294
|
relationshipColumns[`${relationTo}ID`] = getIDColumn({
|
|
288
295
|
name: `${formattedRelationTo}_id`,
|
|
289
296
|
type: colType,
|
|
@@ -357,7 +364,7 @@ export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, di
|
|
|
357
364
|
}
|
|
358
365
|
adapter.relations[`relations_${tableName}`] = relations(table, ({ many, one })=>{
|
|
359
366
|
const result = {};
|
|
360
|
-
nonLocalizedRelations.forEach(({ type, target }, key)=>{
|
|
367
|
+
nonLocalizedRelations.forEach(({ type, relationName, target }, key)=>{
|
|
361
368
|
if (type === 'one') {
|
|
362
369
|
result[key] = one(adapter.tables[target], {
|
|
363
370
|
fields: [
|
|
@@ -371,7 +378,7 @@ export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, di
|
|
|
371
378
|
}
|
|
372
379
|
if (type === 'many') {
|
|
373
380
|
result[key] = many(adapter.tables[target], {
|
|
374
|
-
relationName: key
|
|
381
|
+
relationName: relationName || key
|
|
375
382
|
});
|
|
376
383
|
}
|
|
377
384
|
});
|
|
@@ -398,6 +405,9 @@ export const buildTable = ({ adapter, baseColumns = {}, baseExtraConfig = {}, di
|
|
|
398
405
|
return result;
|
|
399
406
|
});
|
|
400
407
|
return {
|
|
408
|
+
hasLocalizedManyNumberField,
|
|
409
|
+
hasLocalizedManyTextField,
|
|
410
|
+
hasLocalizedRelationshipField,
|
|
401
411
|
hasManyNumberField,
|
|
402
412
|
hasManyTextField,
|
|
403
413
|
relationsToBuild
|
package/dist/schema/build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/build.ts"],"sourcesContent":["import type { Relation } from 'drizzle-orm'\nimport type {\n AnySQLiteColumn,\n ForeignKeyBuilder,\n IndexBuilder,\n SQLiteColumnBuilder,\n SQLiteTableWithColumns,\n UniqueConstraintBuilder,\n} from 'drizzle-orm/sqlite-core'\nimport type { Field } from 'payload'\n\nimport { createTableName } from '@payloadcms/drizzle'\nimport { relations, sql } from 'drizzle-orm'\nimport {\n foreignKey,\n index,\n integer,\n numeric,\n sqliteTable,\n text,\n unique,\n} from 'drizzle-orm/sqlite-core'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { GenericColumns, GenericTable, IDType, SQLiteAdapter } from '../types.js'\n\nimport { getIDColumn } from './getIDColumn.js'\nimport { setColumnID } from './setColumnID.js'\nimport { traverseFields } from './traverseFields.js'\n\nexport type BaseExtraConfig = Record<\n string,\n (cols: {\n [x: string]: AnySQLiteColumn\n }) => ForeignKeyBuilder | IndexBuilder | UniqueConstraintBuilder\n>\n\nexport type RelationMap = Map<string, { localized: boolean; target: string; type: 'many' | 'one' }>\n\ntype Args = {\n adapter: SQLiteAdapter\n baseColumns?: Record<string, SQLiteColumnBuilder>\n /**\n * After table is created, run these functions to add extra config to the table\n * ie. indexes, multiple columns, etc\n */\n baseExtraConfig?: BaseExtraConfig\n buildNumbers?: boolean\n buildRelationships?: boolean\n disableNotNull: boolean\n disableUnique: boolean\n fields: Field[]\n locales?: [string, ...string[]]\n rootRelationsToBuild?: RelationMap\n rootRelationships?: Set<string>\n rootTableIDColType?: IDType\n rootTableName?: string\n tableName: string\n timestamps?: boolean\n versions: boolean\n}\n\ntype Result = {\n hasManyNumberField: 'index' | boolean\n hasManyTextField: 'index' | boolean\n relationsToBuild: RelationMap\n}\n\nexport const buildTable = ({\n adapter,\n baseColumns = {},\n baseExtraConfig = {},\n disableNotNull,\n disableUnique = false,\n fields,\n locales,\n rootRelationsToBuild,\n rootRelationships,\n rootTableIDColType,\n rootTableName: incomingRootTableName,\n tableName,\n timestamps,\n versions,\n}: Args): Result => {\n const isRoot = !incomingRootTableName\n const rootTableName = incomingRootTableName || tableName\n const columns: Record<string, SQLiteColumnBuilder> = baseColumns\n const indexes: Record<string, (cols: GenericColumns) => IndexBuilder> = {}\n\n const localesColumns: Record<string, SQLiteColumnBuilder> = {}\n const localesIndexes: Record<string, (cols: GenericColumns) => IndexBuilder> = {}\n let localesTable: GenericTable | SQLiteTableWithColumns<any>\n let textsTable: GenericTable | SQLiteTableWithColumns<any>\n let numbersTable: GenericTable | SQLiteTableWithColumns<any>\n\n // Relationships to the base collection\n const relationships: Set<string> = rootRelationships || new Set()\n\n let relationshipsTable: GenericTable | SQLiteTableWithColumns<any>\n\n // Drizzle relations\n const relationsToBuild: RelationMap = new Map()\n\n const idColType: IDType = setColumnID({ columns, fields })\n\n const {\n hasLocalizedField,\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n } = traverseFields({\n adapter,\n columns,\n disableNotNull,\n disableUnique,\n fields,\n indexes,\n locales,\n localesColumns,\n localesIndexes,\n newTableName: tableName,\n parentTableName: tableName,\n relationsToBuild,\n relationships,\n rootRelationsToBuild: rootRelationsToBuild || relationsToBuild,\n rootTableIDColType: rootTableIDColType || idColType,\n rootTableName,\n versions,\n })\n\n // split the relationsToBuild by localized and non-localized\n const localizedRelations = new Map()\n const nonLocalizedRelations = new Map()\n\n relationsToBuild.forEach(({ type, localized, target }, key) => {\n const map = localized ? localizedRelations : nonLocalizedRelations\n map.set(key, { type, target })\n })\n\n if (timestamps) {\n columns.createdAt = text('created_at')\n .default(sql`(strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))`)\n .notNull()\n columns.updatedAt = text('updated_at')\n .default(sql`(strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))`)\n .notNull()\n }\n\n const table = sqliteTable(tableName, columns, (cols) => {\n const extraConfig = Object.entries(baseExtraConfig).reduce((config, [key, func]) => {\n config[key] = func(cols)\n return config\n }, {})\n\n const result = Object.entries(indexes).reduce((acc, [colName, func]) => {\n acc[colName] = func(cols)\n return acc\n }, extraConfig)\n\n return result\n })\n\n adapter.tables[tableName] = table\n\n if (hasLocalizedField || localizedRelations.size) {\n const localeTableName = `${tableName}${adapter.localesSuffix}`\n localesColumns.id = integer('id', { mode: 'number' }).primaryKey({ autoIncrement: true })\n localesColumns._locale = text('_locale', { enum: locales }).notNull()\n localesColumns._parentID = getIDColumn({\n name: '_parent_id',\n type: idColType,\n notNull: true,\n primaryKey: false,\n })\n\n localesTable = sqliteTable(localeTableName, localesColumns, (cols) => {\n return Object.entries(localesIndexes).reduce(\n (acc, [colName, func]) => {\n acc[colName] = func(cols)\n return acc\n },\n {\n _localeParent: unique(`${localeTableName}_locale_parent_id_unique`).on(\n cols._locale,\n cols._parentID,\n ),\n _parentIdFk: foreignKey({\n name: `${localeTableName}_parent_id_fk`,\n columns: [cols._parentID],\n foreignColumns: [table.id],\n }).onDelete('cascade'),\n },\n )\n })\n\n adapter.tables[localeTableName] = localesTable\n\n adapter.relations[`relations_${localeTableName}`] = relations(localesTable, ({ many, one }) => {\n const result: Record<string, Relation<string>> = {}\n\n result._parentID = one(table, {\n fields: [localesTable._parentID],\n references: [table.id],\n // name the relationship by what the many() relationName is\n relationName: '_locales',\n })\n\n localizedRelations.forEach(({ type, target }, key) => {\n if (type === 'one') {\n result[key] = one(adapter.tables[target], {\n fields: [localesTable[key]],\n references: [adapter.tables[target].id],\n relationName: key,\n })\n }\n if (type === 'many') {\n result[key] = many(adapter.tables[target], {\n relationName: key,\n })\n }\n })\n\n return result\n })\n }\n\n if (isRoot) {\n if (hasManyTextField) {\n const textsTableName = `${rootTableName}_texts`\n const columns: Record<string, SQLiteColumnBuilder> = {\n id: integer('id', { mode: 'number' }).primaryKey({ autoIncrement: true }),\n order: integer('order').notNull(),\n parent: getIDColumn({\n name: 'parent_id',\n type: idColType,\n notNull: true,\n primaryKey: false,\n }),\n path: text('path').notNull(),\n text: text('text'),\n }\n\n if (hasLocalizedManyTextField) {\n columns.locale = text('locale', { enum: locales })\n }\n\n textsTable = sqliteTable(textsTableName, columns, (cols) => {\n const config: Record<string, ForeignKeyBuilder | IndexBuilder> = {\n orderParentIdx: index(`${textsTableName}_order_parent_idx`).on(cols.order, cols.parent),\n parentFk: foreignKey({\n name: `${textsTableName}_parent_fk`,\n columns: [cols.parent],\n foreignColumns: [table.id],\n }).onDelete('cascade'),\n }\n\n if (hasManyTextField === 'index') {\n config.text_idx = index(`${textsTableName}_text_idx`).on(cols.text)\n }\n\n if (hasLocalizedManyTextField) {\n config.localeParent = index(`${textsTableName}_locale_parent`).on(\n cols.locale,\n cols.parent,\n )\n }\n\n return config\n })\n\n adapter.tables[textsTableName] = textsTable\n\n adapter.relations[`relations_${textsTableName}`] = relations(textsTable, ({ one }) => ({\n parent: one(table, {\n fields: [textsTable.parent],\n references: [table.id],\n relationName: '_texts',\n }),\n }))\n }\n\n if (hasManyNumberField) {\n const numbersTableName = `${rootTableName}_numbers`\n const columns: Record<string, SQLiteColumnBuilder> = {\n id: integer('id', { mode: 'number' }).primaryKey({ autoIncrement: true }),\n number: numeric('number'),\n order: integer('order').notNull(),\n parent: getIDColumn({\n name: 'parent_id',\n type: idColType,\n notNull: true,\n primaryKey: false,\n }),\n path: text('path').notNull(),\n }\n\n if (hasLocalizedManyNumberField) {\n columns.locale = text('locale', { enum: locales })\n }\n\n numbersTable = sqliteTable(numbersTableName, columns, (cols) => {\n const config: Record<string, ForeignKeyBuilder | IndexBuilder> = {\n orderParentIdx: index(`${numbersTableName}_order_parent_idx`).on(cols.order, cols.parent),\n parentFk: foreignKey({\n name: `${numbersTableName}_parent_fk`,\n columns: [cols.parent],\n foreignColumns: [table.id],\n }).onDelete('cascade'),\n }\n\n if (hasManyNumberField === 'index') {\n config.numberIdx = index(`${numbersTableName}_number_idx`).on(cols.number)\n }\n\n if (hasLocalizedManyNumberField) {\n config.localeParent = index(`${numbersTableName}_locale_parent`).on(\n cols.locale,\n cols.parent,\n )\n }\n\n return config\n })\n\n adapter.tables[numbersTableName] = numbersTable\n\n adapter.relations[`relations_${numbersTableName}`] = relations(numbersTable, ({ one }) => ({\n parent: one(table, {\n fields: [numbersTable.parent],\n references: [table.id],\n relationName: '_numbers',\n }),\n }))\n }\n\n if (relationships.size) {\n const relationshipColumns: Record<string, SQLiteColumnBuilder> = {\n id: integer('id', { mode: 'number' }).primaryKey({ autoIncrement: true }),\n order: integer('order'),\n parent: getIDColumn({\n name: 'parent_id',\n type: idColType,\n notNull: true,\n primaryKey: false,\n }),\n path: text('path').notNull(),\n }\n\n if (hasLocalizedRelationshipField) {\n relationshipColumns.locale = text('locale', { enum: locales })\n }\n\n const relationExtraConfig: BaseExtraConfig = {}\n const relationshipsTableName = `${tableName}${adapter.relationshipsSuffix}`\n\n relationships.forEach((relationTo) => {\n const relationshipConfig = adapter.payload.collections[relationTo].config\n const formattedRelationTo = createTableName({\n adapter,\n config: relationshipConfig,\n })\n let colType: IDType = 'integer'\n const relatedCollectionCustomIDType =\n adapter.payload.collections[relationshipConfig.slug]?.customIDType\n\n if (relatedCollectionCustomIDType === 'number') colType = 'numeric'\n if (relatedCollectionCustomIDType === 'text') colType = 'text'\n\n relationshipColumns[`${relationTo}ID`] = getIDColumn({\n name: `${formattedRelationTo}_id`,\n type: colType,\n primaryKey: false,\n })\n\n relationExtraConfig[`${relationTo}IdFk`] = (cols) =>\n foreignKey({\n name: `${relationshipsTableName}_${toSnakeCase(relationTo)}_fk`,\n columns: [cols[`${relationTo}ID`]],\n foreignColumns: [adapter.tables[formattedRelationTo].id],\n }).onDelete('cascade')\n })\n\n relationshipsTable = sqliteTable(relationshipsTableName, relationshipColumns, (cols) => {\n const result: Record<string, ForeignKeyBuilder | IndexBuilder> = Object.entries(\n relationExtraConfig,\n ).reduce(\n (config, [key, func]) => {\n config[key] = func(cols)\n return config\n },\n {\n order: index(`${relationshipsTableName}_order_idx`).on(cols.order),\n parentFk: foreignKey({\n name: `${relationshipsTableName}_parent_fk`,\n columns: [cols.parent],\n foreignColumns: [table.id],\n }).onDelete('cascade'),\n parentIdx: index(`${relationshipsTableName}_parent_idx`).on(cols.parent),\n pathIdx: index(`${relationshipsTableName}_path_idx`).on(cols.path),\n },\n )\n\n if (hasLocalizedRelationshipField) {\n result.localeIdx = index(`${relationshipsTableName}_locale_idx`).on(cols.locale)\n }\n\n return result\n })\n\n adapter.tables[relationshipsTableName] = relationshipsTable\n\n adapter.relations[`relations_${relationshipsTableName}`] = relations(\n relationshipsTable,\n ({ one }) => {\n const result: Record<string, Relation<string>> = {\n parent: one(table, {\n fields: [relationshipsTable.parent],\n references: [table.id],\n relationName: '_rels',\n }),\n }\n\n relationships.forEach((relationTo) => {\n const relatedTableName = createTableName({\n adapter,\n config: adapter.payload.collections[relationTo].config,\n })\n const idColumnName = `${relationTo}ID`\n result[idColumnName] = one(adapter.tables[relatedTableName], {\n fields: [relationshipsTable[idColumnName]],\n references: [adapter.tables[relatedTableName].id],\n relationName: relationTo,\n })\n })\n\n return result\n },\n )\n }\n }\n\n adapter.relations[`relations_${tableName}`] = relations(table, ({ many, one }) => {\n const result: Record<string, Relation<string>> = {}\n\n nonLocalizedRelations.forEach(({ type, target }, key) => {\n if (type === 'one') {\n result[key] = one(adapter.tables[target], {\n fields: [table[key]],\n references: [adapter.tables[target].id],\n relationName: key,\n })\n }\n if (type === 'many') {\n result[key] = many(adapter.tables[target], { relationName: key })\n }\n })\n\n if (hasLocalizedField) {\n result._locales = many(localesTable, { relationName: '_locales' })\n }\n\n if (hasManyTextField) {\n result._texts = many(textsTable, { relationName: '_texts' })\n }\n\n if (hasManyNumberField) {\n result._numbers = many(numbersTable, { relationName: '_numbers' })\n }\n\n if (relationships.size && relationshipsTable) {\n result._rels = many(relationshipsTable, {\n relationName: '_rels',\n })\n }\n\n return result\n })\n\n return { hasManyNumberField, hasManyTextField, relationsToBuild }\n}\n"],"names":["createTableName","relations","sql","foreignKey","index","integer","numeric","sqliteTable","text","unique","toSnakeCase","getIDColumn","setColumnID","traverseFields","buildTable","adapter","baseColumns","baseExtraConfig","disableNotNull","disableUnique","fields","locales","rootRelationsToBuild","rootRelationships","rootTableIDColType","rootTableName","incomingRootTableName","tableName","timestamps","versions","isRoot","columns","indexes","localesColumns","localesIndexes","localesTable","textsTable","numbersTable","relationships","Set","relationshipsTable","relationsToBuild","Map","idColType","hasLocalizedField","hasLocalizedManyNumberField","hasLocalizedManyTextField","hasLocalizedRelationshipField","hasManyNumberField","hasManyTextField","newTableName","parentTableName","localizedRelations","nonLocalizedRelations","forEach","type","localized","target","key","map","set","createdAt","default","notNull","updatedAt","table","cols","extraConfig","Object","entries","reduce","config","func","result","acc","colName","tables","size","localeTableName","localesSuffix","id","mode","primaryKey","autoIncrement","_locale","enum","_parentID","name","_localeParent","on","_parentIdFk","foreignColumns","onDelete","many","one","references","relationName","textsTableName","order","parent","path","locale","orderParentIdx","parentFk","text_idx","localeParent","numbersTableName","number","numberIdx","relationshipColumns","relationExtraConfig","relationshipsTableName","relationshipsSuffix","relationTo","relationshipConfig","payload","collections","formattedRelationTo","colType","relatedCollectionCustomIDType","slug","customIDType","parentIdx","pathIdx","localeIdx","relatedTableName","idColumnName","_locales","_texts","_numbers","_rels"],"mappings":"AAWA,SAASA,eAAe,QAAQ,sBAAqB;AACrD,SAASC,SAAS,EAAEC,GAAG,QAAQ,cAAa;AAC5C,SACEC,UAAU,EACVC,KAAK,EACLC,OAAO,EACPC,OAAO,EACPC,WAAW,EACXC,IAAI,EACJC,MAAM,QACD,0BAAyB;AAChC,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,cAAc,QAAQ,sBAAqB;AAwCpD,OAAO,MAAMC,aAAa,CAAC,EACzBC,OAAO,EACPC,cAAc,CAAC,CAAC,EAChBC,kBAAkB,CAAC,CAAC,EACpBC,cAAc,EACdC,gBAAgB,KAAK,EACrBC,MAAM,EACNC,OAAO,EACPC,oBAAoB,EACpBC,iBAAiB,EACjBC,kBAAkB,EAClBC,eAAeC,qBAAqB,EACpCC,SAAS,EACTC,UAAU,EACVC,QAAQ,EACH;IACL,MAAMC,SAAS,CAACJ;IAChB,MAAMD,gBAAgBC,yBAAyBC;IAC/C,MAAMI,UAA+Cf;IACrD,MAAMgB,UAAkE,CAAC;IAEzE,MAAMC,iBAAsD,CAAC;IAC7D,MAAMC,iBAAyE,CAAC;IAChF,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IAEJ,uCAAuC;IACvC,MAAMC,gBAA6Bf,qBAAqB,IAAIgB;IAE5D,IAAIC;IAEJ,oBAAoB;IACpB,MAAMC,mBAAgC,IAAIC;IAE1C,MAAMC,YAAoB/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AAM,CAACf,IAAI,GAAGmC,KAAK9E,QAAQ6D,MAAM,CAACnB,OAAO,EAAE;oBAAEuC,cAActC;gBAAI;YACjE;QACF;QAEA,IAAId,mBAAmB;YACrB6B,OAAOsD,QAAQ,GAAGlC,KAAK1D,cAAc;gBAAE6D,cAAc;YAAW;QAClE;QAEA,IAAI/C,kBAAkB;YACpBwB,OAAOuD,MAAM,GAAGnC,KAAKzD,YAAY;gBAAE4D,cAAc;YAAS;QAC5D;QAEA,IAAIhD,oBAAoB;YACtByB,OAAOwD,QAAQ,GAAGpC,KAAKxD,cAAc;gBAAE2D,cAAc;YAAW;QAClE;QAEA,IAAI1D,cAAcuC,IAAI,IAAIrC,oBAAoB;YAC5CiC,OAAOyD,KAAK,GAAGrC,KAAKrD,oBAAoB;gBACtCwD,cAAc;YAChB;QACF;QAEA,OAAOvB;IACT;IAEA,OAAO;QAAEzB;QAAoBC;QAAkBR;IAAiB;AAClE,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/schema/build.ts"],"sourcesContent":["import type { Relation } from 'drizzle-orm'\nimport type {\n AnySQLiteColumn,\n ForeignKeyBuilder,\n IndexBuilder,\n SQLiteColumnBuilder,\n SQLiteTableWithColumns,\n UniqueConstraintBuilder,\n} from 'drizzle-orm/sqlite-core'\nimport type { Field, SanitizedJoins } from 'payload'\n\nimport { createTableName } from '@payloadcms/drizzle'\nimport { relations, sql } from 'drizzle-orm'\nimport {\n foreignKey,\n index,\n integer,\n numeric,\n sqliteTable,\n text,\n unique,\n} from 'drizzle-orm/sqlite-core'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { GenericColumns, GenericTable, IDType, SQLiteAdapter } from '../types.js'\n\nimport { getIDColumn } from './getIDColumn.js'\nimport { setColumnID } from './setColumnID.js'\nimport { traverseFields } from './traverseFields.js'\n\nexport type BaseExtraConfig = Record<\n string,\n (cols: {\n [x: string]: AnySQLiteColumn\n }) => ForeignKeyBuilder | IndexBuilder | UniqueConstraintBuilder\n>\n\nexport type RelationMap = Map<\n string,\n {\n localized: boolean\n relationName?: string\n target: string\n type: 'many' | 'one'\n }\n>\n\ntype Args = {\n adapter: SQLiteAdapter\n baseColumns?: Record<string, SQLiteColumnBuilder>\n /**\n * After table is created, run these functions to add extra config to the table\n * ie. indexes, multiple columns, etc\n */\n baseExtraConfig?: BaseExtraConfig\n buildNumbers?: boolean\n buildRelationships?: boolean\n disableNotNull: boolean\n disableUnique: boolean\n fields: Field[]\n joins?: SanitizedJoins\n locales?: [string, ...string[]]\n rootRelationships?: Set<string>\n rootRelationsToBuild?: RelationMap\n rootTableIDColType?: IDType\n rootTableName?: string\n tableName: string\n timestamps?: boolean\n versions: boolean\n /**\n * Tracks whether or not this table is built\n * from the result of a localized array or block field at some point\n */\n withinLocalizedArrayOrBlock?: boolean\n}\n\ntype Result = {\n hasLocalizedManyNumberField: boolean\n hasLocalizedManyTextField: boolean\n hasLocalizedRelationshipField: boolean\n hasManyNumberField: 'index' | boolean\n hasManyTextField: 'index' | boolean\n relationsToBuild: RelationMap\n}\n\nexport const buildTable = ({\n adapter,\n baseColumns = {},\n baseExtraConfig = {},\n disableNotNull,\n disableUnique = false,\n fields,\n joins,\n locales,\n rootRelationships,\n rootRelationsToBuild,\n rootTableIDColType,\n rootTableName: incomingRootTableName,\n tableName,\n timestamps,\n versions,\n withinLocalizedArrayOrBlock,\n}: Args): Result => {\n const isRoot = !incomingRootTableName\n const rootTableName = incomingRootTableName || tableName\n const columns: Record<string, SQLiteColumnBuilder> = baseColumns\n const indexes: Record<string, (cols: GenericColumns) => IndexBuilder> = {}\n\n const localesColumns: Record<string, SQLiteColumnBuilder> = {}\n const localesIndexes: Record<string, (cols: GenericColumns) => IndexBuilder> = {}\n let localesTable: GenericTable | SQLiteTableWithColumns<any>\n let textsTable: GenericTable | SQLiteTableWithColumns<any>\n let numbersTable: GenericTable | SQLiteTableWithColumns<any>\n\n // Relationships to the base collection\n const relationships: Set<string> = rootRelationships || new Set()\n\n let relationshipsTable: GenericTable | SQLiteTableWithColumns<any>\n\n // Drizzle relations\n const relationsToBuild: RelationMap = new Map()\n\n const idColType: IDType = setColumnID({ columns, fields })\n\n const {\n hasLocalizedField,\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n } = traverseFields({\n adapter,\n columns,\n disableNotNull,\n disableUnique,\n fields,\n indexes,\n joins,\n locales,\n localesColumns,\n localesIndexes,\n newTableName: tableName,\n parentTableName: tableName,\n relationships,\n relationsToBuild,\n rootRelationsToBuild: rootRelationsToBuild || relationsToBuild,\n rootTableIDColType: rootTableIDColType || idColType,\n rootTableName,\n versions,\n withinLocalizedArrayOrBlock,\n })\n\n // split the relationsToBuild by localized and non-localized\n const localizedRelations = new Map()\n const nonLocalizedRelations = new Map()\n\n relationsToBuild.forEach(({ type, localized, relationName, target }, key) => {\n const map = localized ? localizedRelations : nonLocalizedRelations\n map.set(key, { type, relationName, target })\n })\n\n if (timestamps) {\n columns.createdAt = text('created_at')\n .default(sql`(strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))`)\n .notNull()\n columns.updatedAt = text('updated_at')\n .default(sql`(strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))`)\n .notNull()\n }\n\n const table = sqliteTable(tableName, columns, (cols) => {\n const extraConfig = Object.entries(baseExtraConfig).reduce((config, [key, func]) => {\n config[key] = func(cols)\n return config\n }, {})\n\n const result = Object.entries(indexes).reduce((acc, [colName, func]) => {\n acc[colName] = func(cols)\n return acc\n }, extraConfig)\n\n return result\n })\n\n adapter.tables[tableName] = table\n\n if (hasLocalizedField || localizedRelations.size) {\n const localeTableName = `${tableName}${adapter.localesSuffix}`\n localesColumns.id = integer('id', { mode: 'number' }).primaryKey({ autoIncrement: true })\n localesColumns._locale = text('_locale', { enum: locales }).notNull()\n localesColumns._parentID = getIDColumn({\n name: '_parent_id',\n type: idColType,\n notNull: true,\n primaryKey: false,\n })\n\n localesTable = sqliteTable(localeTableName, localesColumns, (cols) => {\n return Object.entries(localesIndexes).reduce(\n (acc, [colName, func]) => {\n acc[colName] = func(cols)\n return acc\n },\n {\n _localeParent: unique(`${localeTableName}_locale_parent_id_unique`).on(\n cols._locale,\n cols._parentID,\n ),\n _parentIdFk: foreignKey({\n name: `${localeTableName}_parent_id_fk`,\n columns: [cols._parentID],\n foreignColumns: [table.id],\n }).onDelete('cascade'),\n },\n )\n })\n\n adapter.tables[localeTableName] = localesTable\n\n adapter.relations[`relations_${localeTableName}`] = relations(localesTable, ({ many, one }) => {\n const result: Record<string, Relation<string>> = {}\n\n result._parentID = one(table, {\n fields: [localesTable._parentID],\n references: [table.id],\n // name the relationship by what the many() relationName is\n relationName: '_locales',\n })\n\n localizedRelations.forEach(({ type, target }, key) => {\n if (type === 'one') {\n result[key] = one(adapter.tables[target], {\n fields: [localesTable[key]],\n references: [adapter.tables[target].id],\n relationName: key,\n })\n }\n if (type === 'many') {\n result[key] = many(adapter.tables[target], {\n relationName: key,\n })\n }\n })\n\n return result\n })\n }\n\n if (isRoot) {\n if (hasManyTextField) {\n const textsTableName = `${rootTableName}_texts`\n const columns: Record<string, SQLiteColumnBuilder> = {\n id: integer('id', { mode: 'number' }).primaryKey({ autoIncrement: true }),\n order: integer('order').notNull(),\n parent: getIDColumn({\n name: 'parent_id',\n type: idColType,\n notNull: true,\n primaryKey: false,\n }),\n path: text('path').notNull(),\n text: text('text'),\n }\n\n if (hasLocalizedManyTextField) {\n columns.locale = text('locale', { enum: locales })\n }\n\n textsTable = sqliteTable(textsTableName, columns, (cols) => {\n const config: Record<string, ForeignKeyBuilder | IndexBuilder> = {\n orderParentIdx: index(`${textsTableName}_order_parent_idx`).on(cols.order, cols.parent),\n parentFk: foreignKey({\n name: `${textsTableName}_parent_fk`,\n columns: [cols.parent],\n foreignColumns: [table.id],\n }).onDelete('cascade'),\n }\n\n if (hasManyTextField === 'index') {\n config.text_idx = index(`${textsTableName}_text_idx`).on(cols.text)\n }\n\n if (hasLocalizedManyTextField) {\n config.localeParent = index(`${textsTableName}_locale_parent`).on(\n cols.locale,\n cols.parent,\n )\n }\n\n return config\n })\n\n adapter.tables[textsTableName] = textsTable\n\n adapter.relations[`relations_${textsTableName}`] = relations(textsTable, ({ one }) => ({\n parent: one(table, {\n fields: [textsTable.parent],\n references: [table.id],\n relationName: '_texts',\n }),\n }))\n }\n\n if (hasManyNumberField) {\n const numbersTableName = `${rootTableName}_numbers`\n const columns: Record<string, SQLiteColumnBuilder> = {\n id: integer('id', { mode: 'number' }).primaryKey({ autoIncrement: true }),\n number: numeric('number'),\n order: integer('order').notNull(),\n parent: getIDColumn({\n name: 'parent_id',\n type: idColType,\n notNull: true,\n primaryKey: false,\n }),\n path: text('path').notNull(),\n }\n\n if (hasLocalizedManyNumberField) {\n columns.locale = text('locale', { enum: locales })\n }\n\n numbersTable = sqliteTable(numbersTableName, columns, (cols) => {\n const config: Record<string, ForeignKeyBuilder | IndexBuilder> = {\n orderParentIdx: index(`${numbersTableName}_order_parent_idx`).on(cols.order, cols.parent),\n parentFk: foreignKey({\n name: `${numbersTableName}_parent_fk`,\n columns: [cols.parent],\n foreignColumns: [table.id],\n }).onDelete('cascade'),\n }\n\n if (hasManyNumberField === 'index') {\n config.numberIdx = index(`${numbersTableName}_number_idx`).on(cols.number)\n }\n\n if (hasLocalizedManyNumberField) {\n config.localeParent = index(`${numbersTableName}_locale_parent`).on(\n cols.locale,\n cols.parent,\n )\n }\n\n return config\n })\n\n adapter.tables[numbersTableName] = numbersTable\n\n adapter.relations[`relations_${numbersTableName}`] = relations(numbersTable, ({ one }) => ({\n parent: one(table, {\n fields: [numbersTable.parent],\n references: [table.id],\n relationName: '_numbers',\n }),\n }))\n }\n\n if (relationships.size) {\n const relationshipColumns: Record<string, SQLiteColumnBuilder> = {\n id: integer('id', { mode: 'number' }).primaryKey({ autoIncrement: true }),\n order: integer('order'),\n parent: getIDColumn({\n name: 'parent_id',\n type: idColType,\n notNull: true,\n primaryKey: false,\n }),\n path: text('path').notNull(),\n }\n\n if (hasLocalizedRelationshipField) {\n relationshipColumns.locale = text('locale', { enum: locales })\n }\n\n const relationExtraConfig: BaseExtraConfig = {}\n const relationshipsTableName = `${tableName}${adapter.relationshipsSuffix}`\n\n relationships.forEach((relationTo) => {\n const relationshipConfig = adapter.payload.collections[relationTo].config\n const formattedRelationTo = createTableName({\n adapter,\n config: relationshipConfig,\n })\n let colType: IDType = 'integer'\n const relatedCollectionCustomIDType =\n adapter.payload.collections[relationshipConfig.slug]?.customIDType\n\n if (relatedCollectionCustomIDType === 'number') {\n colType = 'numeric'\n }\n if (relatedCollectionCustomIDType === 'text') {\n colType = 'text'\n }\n\n relationshipColumns[`${relationTo}ID`] = getIDColumn({\n name: `${formattedRelationTo}_id`,\n type: colType,\n primaryKey: false,\n })\n\n relationExtraConfig[`${relationTo}IdFk`] = (cols) =>\n foreignKey({\n name: `${relationshipsTableName}_${toSnakeCase(relationTo)}_fk`,\n columns: [cols[`${relationTo}ID`]],\n foreignColumns: [adapter.tables[formattedRelationTo].id],\n }).onDelete('cascade')\n })\n\n relationshipsTable = sqliteTable(relationshipsTableName, relationshipColumns, (cols) => {\n const result: Record<string, ForeignKeyBuilder | IndexBuilder> = Object.entries(\n relationExtraConfig,\n ).reduce(\n (config, [key, func]) => {\n config[key] = func(cols)\n return config\n },\n {\n order: index(`${relationshipsTableName}_order_idx`).on(cols.order),\n parentFk: foreignKey({\n name: `${relationshipsTableName}_parent_fk`,\n columns: [cols.parent],\n foreignColumns: [table.id],\n }).onDelete('cascade'),\n parentIdx: index(`${relationshipsTableName}_parent_idx`).on(cols.parent),\n pathIdx: index(`${relationshipsTableName}_path_idx`).on(cols.path),\n },\n )\n\n if (hasLocalizedRelationshipField) {\n result.localeIdx = index(`${relationshipsTableName}_locale_idx`).on(cols.locale)\n }\n\n return result\n })\n\n adapter.tables[relationshipsTableName] = relationshipsTable\n\n adapter.relations[`relations_${relationshipsTableName}`] = relations(\n relationshipsTable,\n ({ one }) => {\n const result: Record<string, Relation<string>> = {\n parent: one(table, {\n fields: [relationshipsTable.parent],\n references: [table.id],\n relationName: '_rels',\n }),\n }\n\n relationships.forEach((relationTo) => {\n const relatedTableName = createTableName({\n adapter,\n config: adapter.payload.collections[relationTo].config,\n })\n const idColumnName = `${relationTo}ID`\n result[idColumnName] = one(adapter.tables[relatedTableName], {\n fields: [relationshipsTable[idColumnName]],\n references: [adapter.tables[relatedTableName].id],\n relationName: relationTo,\n })\n })\n\n return result\n },\n )\n }\n }\n\n adapter.relations[`relations_${tableName}`] = relations(table, ({ many, one }) => {\n const result: Record<string, Relation<string>> = {}\n\n nonLocalizedRelations.forEach(({ type, relationName, target }, key) => {\n if (type === 'one') {\n result[key] = one(adapter.tables[target], {\n fields: [table[key]],\n references: [adapter.tables[target].id],\n relationName: key,\n })\n }\n if (type === 'many') {\n result[key] = many(adapter.tables[target], { relationName: relationName || key })\n }\n })\n\n if (hasLocalizedField) {\n result._locales = many(localesTable, { relationName: '_locales' })\n }\n\n if (hasManyTextField) {\n result._texts = many(textsTable, { relationName: '_texts' })\n }\n\n if (hasManyNumberField) {\n result._numbers = many(numbersTable, { relationName: '_numbers' })\n }\n\n if (relationships.size && relationshipsTable) {\n result._rels = many(relationshipsTable, {\n relationName: '_rels',\n })\n }\n\n return result\n })\n\n return {\n hasLocalizedManyNumberField,\n hasLocalizedManyTextField,\n hasLocalizedRelationshipField,\n hasManyNumberField,\n hasManyTextField,\n relationsToBuild,\n }\n}\n"],"names":["createTableName","relations","sql","foreignKey","index","integer","numeric","sqliteTable","text","unique","toSnakeCase","getIDColumn","setColumnID","traverseFields","buildTable","adapter","baseColumns","baseExtraConfig","disableNotNull","disableUnique","fields","joins","locales","rootRelationships","rootRelationsToBuild","rootTableIDColType","rootTableName","incomingRootTableName","tableName","timestamps","versions","withinLocalizedArrayOrBlock","isRoot","columns","indexes","localesColumns","localesIndexes","localesTable","textsTable","numbersTable","relationships","Set","relationshipsTable","relationsToBuild","Map","idColType","hasLocalizedField","hasLocalizedManyNumberField","hasLocalizedManyTextField","hasLocalizedRelationshipField","hasManyNumberField","hasManyTextField","newTableName","parentTableName","localizedRelations","nonLocalizedRelations","forEach","type","localized","relationName","target","key","map","set","createdAt","default","notNull","updatedAt","table","cols","extraConfig","Object","entries","reduce","config","func","result","acc","colName","tables","size","localeTableName","localesSuffix","id","mode","primaryKey","autoIncrement","_locale","enum","_parentID","name","_localeParent","on","_parentIdFk","foreignColumns","onDelete","many","one","references","textsTableName","order","parent","path","locale","orderParentIdx","parentFk","text_idx","localeParent","numbersTableName","number","numberIdx","relationshipColumns","relationExtraConfig","relationshipsTableName","relationshipsSuffix","relationTo","relationshipConfig","payload","collections","formattedRelationTo","colType","relatedCollectionCustomIDType","slug","customIDType","parentIdx","pathIdx","localeIdx","relatedTableName","idColumnName","_locales","_texts","_numbers","_rels"],"mappings":"AAWA,SAASA,eAAe,QAAQ,sBAAqB;AACrD,SAASC,SAAS,EAAEC,GAAG,QAAQ,cAAa;AAC5C,SACEC,UAAU,EACVC,KAAK,EACLC,OAAO,EACPC,OAAO,EACPC,WAAW,EACXC,IAAI,EACJC,MAAM,QACD,0BAAyB;AAChC,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,cAAc,QAAQ,sBAAqB;AAyDpD,OAAO,MAAMC,aAAa,CAAC,EACzBC,OAAO,EACPC,cAAc,CAAC,CAAC,EAChBC,kBAAkB,CAAC,CAAC,EACpBC,cAAc,EACdC,gBAAgB,KAAK,EACrBC,MAAM,EACNC,KAAK,EACLC,OAAO,EACPC,iBAAiB,EACjBC,oBAAoB,EACpBC,kBAAkB,EAClBC,eAAeC,qBAAqB,EACpCC,SAAS,EACTC,UAAU,EACVC,QAAQ,EACRC,2BAA2B,EACtB;IACL,MAAMC,SAAS,CAACL;IAChB,MAAMD,gBAAgBC,yBAAyBC;IAC/C,MAAMK,UAA+CjB;IACrD,MAAMk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C,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,WAAW,4CAA6C,eAAe,aACnE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,eAAe,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"createIndex.d.ts","sourceRoot":"","sources":["../../src/schema/createIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAI9D,KAAK,eAAe,GAAG;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACvB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,WAAW,4CAA6C,eAAe,aACnE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,eAAe,CAAA;CAAE,mDAehD,CAAA"}
|
|
@@ -10,7 +10,9 @@ export const createIndex = ({ name, columnName, tableName, unique })=>{
|
|
|
10
10
|
table[name]
|
|
11
11
|
];
|
|
12
12
|
}
|
|
13
|
-
if (unique)
|
|
13
|
+
if (unique) {
|
|
14
|
+
return uniqueIndex(`${tableName}_${columnName}_idx`).on(columns[0], ...columns.slice(1));
|
|
15
|
+
}
|
|
14
16
|
return index(`${tableName}_${columnName}_idx`).on(columns[0], ...columns.slice(1));
|
|
15
17
|
};
|
|
16
18
|
};
|