@payloadcms/db-sqlite 3.0.0-canary.2c2c95f
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/README.md +30 -0
- package/dist/connect.d.ts +3 -0
- package/dist/connect.d.ts.map +1 -0
- package/dist/connect.js +42 -0
- package/dist/connect.js.map +1 -0
- package/dist/countDistinct.d.ts +3 -0
- package/dist/countDistinct.d.ts.map +1 -0
- package/dist/countDistinct.js +24 -0
- package/dist/countDistinct.js.map +1 -0
- package/dist/createJSONQuery/convertPathToJSONTraversal.d.ts +2 -0
- package/dist/createJSONQuery/convertPathToJSONTraversal.d.ts.map +1 -0
- package/dist/createJSONQuery/convertPathToJSONTraversal.js +12 -0
- package/dist/createJSONQuery/convertPathToJSONTraversal.js.map +1 -0
- package/dist/createJSONQuery/index.d.ts +3 -0
- package/dist/createJSONQuery/index.d.ts.map +1 -0
- package/dist/createJSONQuery/index.js +54 -0
- package/dist/createJSONQuery/index.js.map +1 -0
- package/dist/createMigration.d.ts +3 -0
- package/dist/createMigration.d.ts.map +1 -0
- package/dist/createMigration.js +81 -0
- package/dist/createMigration.js.map +1 -0
- package/dist/defaultSnapshot.d.ts +3 -0
- package/dist/defaultSnapshot.d.ts.map +1 -0
- package/dist/defaultSnapshot.js +14 -0
- package/dist/defaultSnapshot.js.map +1 -0
- package/dist/deleteWhere.d.ts +3 -0
- package/dist/deleteWhere.d.ts.map +1 -0
- package/dist/deleteWhere.js +6 -0
- package/dist/deleteWhere.js.map +1 -0
- package/dist/dropDatabase.d.ts +3 -0
- package/dist/dropDatabase.d.ts.map +1 -0
- package/dist/dropDatabase.js +19 -0
- package/dist/dropDatabase.js.map +1 -0
- package/dist/execute.d.ts +3 -0
- package/dist/execute.d.ts.map +1 -0
- package/dist/execute.js +13 -0
- package/dist/execute.js.map +1 -0
- package/dist/generateDrizzleJSON.d.ts +3 -0
- package/dist/generateDrizzleJSON.d.ts.map +1 -0
- package/dist/generateDrizzleJSON.js +8 -0
- package/dist/generateDrizzleJSON.js.map +1 -0
- package/dist/getMigrationTemplate.d.ts +3 -0
- package/dist/getMigrationTemplate.d.ts.map +1 -0
- package/dist/getMigrationTemplate.js +12 -0
- package/dist/getMigrationTemplate.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +116 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +3 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +88 -0
- package/dist/init.js.map +1 -0
- package/dist/insert.d.ts +3 -0
- package/dist/insert.d.ts.map +1 -0
- package/dist/insert.js +13 -0
- package/dist/insert.js.map +1 -0
- package/dist/requireDrizzleKit.d.ts +3 -0
- package/dist/requireDrizzleKit.d.ts.map +1 -0
- package/dist/requireDrizzleKit.js +10 -0
- package/dist/requireDrizzleKit.js.map +1 -0
- package/dist/schema/build.d.ts +49 -0
- package/dist/schema/build.d.ts.map +1 -0
- package/dist/schema/build.js +407 -0
- package/dist/schema/build.js.map +1 -0
- package/dist/schema/createIndex.d.ts +12 -0
- package/dist/schema/createIndex.d.ts.map +1 -0
- package/dist/schema/createIndex.js +18 -0
- package/dist/schema/createIndex.js.map +1 -0
- package/dist/schema/getIDColumn.d.ts +8 -0
- package/dist/schema/getIDColumn.d.ts.map +1 -0
- package/dist/schema/getIDColumn.js +24 -0
- package/dist/schema/getIDColumn.js.map +1 -0
- package/dist/schema/idToUUID.d.ts +3 -0
- package/dist/schema/idToUUID.d.ts.map +1 -0
- package/dist/schema/idToUUID.js +11 -0
- package/dist/schema/idToUUID.js.map +1 -0
- package/dist/schema/setColumnID.d.ts +10 -0
- package/dist/schema/setColumnID.d.ts.map +1 -0
- package/dist/schema/setColumnID.js +20 -0
- package/dist/schema/setColumnID.js.map +1 -0
- package/dist/schema/traverseFields.d.ts +37 -0
- package/dist/schema/traverseFields.d.ts.map +1 -0
- package/dist/schema/traverseFields.js +633 -0
- package/dist/schema/traverseFields.js.map +1 -0
- package/dist/types.d.ts +136 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Payload Postgres Adapter
|
|
2
|
+
|
|
3
|
+
Official SQLite adapter for [Payload](https://payloadcms.com).
|
|
4
|
+
|
|
5
|
+
- [Main Repository](https://github.com/payloadcms/payload)
|
|
6
|
+
- [Payload Docs](https://payloadcms.com/docs)
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @payloadcms/db-sqlite
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { buildConfig } from 'payload/config'
|
|
18
|
+
import { sqliteAdapter } from '@payloadcms/db-sqlite'
|
|
19
|
+
|
|
20
|
+
export default buildConfig({
|
|
21
|
+
db: sqliteAdapter({
|
|
22
|
+
client: {
|
|
23
|
+
url: process.env.DATABASE_URI,
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
// ...rest of config
|
|
27
|
+
})
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
More detailed usage can be found in the [Payload Docs](https://payloadcms.com/docs/configuration/overview).
|
|
@@ -0,0 +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,OA4CrB,CAAA"}
|
package/dist/connect.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createClient } from '@libsql/client';
|
|
2
|
+
import { pushDevSchema } from '@payloadcms/drizzle';
|
|
3
|
+
import { drizzle } from 'drizzle-orm/libsql';
|
|
4
|
+
export const connect = async function connect(options = {
|
|
5
|
+
hotReload: false
|
|
6
|
+
}) {
|
|
7
|
+
const { hotReload } = options;
|
|
8
|
+
this.schema = {
|
|
9
|
+
...this.tables,
|
|
10
|
+
...this.relations
|
|
11
|
+
};
|
|
12
|
+
try {
|
|
13
|
+
if (!this.client) {
|
|
14
|
+
this.client = createClient(this.clientConfig);
|
|
15
|
+
}
|
|
16
|
+
const logger = this.logger || false;
|
|
17
|
+
this.drizzle = drizzle(this.client, {
|
|
18
|
+
logger,
|
|
19
|
+
schema: this.schema
|
|
20
|
+
});
|
|
21
|
+
if (!hotReload) {
|
|
22
|
+
if (process.env.PAYLOAD_DROP_DATABASE === 'true') {
|
|
23
|
+
this.payload.logger.info(`---- DROPPING TABLES ----`);
|
|
24
|
+
await this.dropDatabase({
|
|
25
|
+
adapter: this
|
|
26
|
+
});
|
|
27
|
+
this.payload.logger.info('---- DROPPED TABLES ----');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
} catch (err) {
|
|
31
|
+
this.payload.logger.error(`Error: cannot connect to SQLite. Details: ${err.message}`, err);
|
|
32
|
+
if (typeof this.rejectInitializing === 'function') this.rejectInitializing();
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
// Only push schema if not in production
|
|
36
|
+
if (process.env.NODE_ENV !== 'production' && process.env.PAYLOAD_MIGRATING !== 'true' && this.push !== false) {
|
|
37
|
+
await pushDevSchema(this);
|
|
38
|
+
}
|
|
39
|
+
if (typeof this.resolveInitializing === 'function') this.resolveInitializing();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=connect.js.map
|
|
@@ -0,0 +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 }) as LibSQLDatabase\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(`Error: cannot connect to SQLite. 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"],"names":["createClient","pushDevSchema","drizzle","connect","options","hotReload","schema","tables","relations","client","clientConfig","logger","process","env","PAYLOAD_DROP_DATABASE","payload","info","dropDatabase","adapter","err","error","message","rejectInitializing","exit","NODE_ENV","PAYLOAD_MIGRATING","push","resolveInitializing"],"mappings":"AAIA,SAASA,YAAY,QAAQ,iBAAgB;AAC7C,SAASC,aAAa,QAAQ,sBAAqB;AACnD,SAASC,OAAO,QAAQ,qBAAoB;AAI5C,OAAO,MAAMC,UAAmB,eAAeA,QAE7CC,UAAU;IACRC,WAAW;AACb,CAAC;IAED,MAAM,EAAEA,SAAS,EAAE,GAAGD;IAEtB,IAAI,CAACE,MAAM,GAAG;QACZ,GAAG,IAAI,CAACC,MAAM;QACd,GAAG,IAAI,CAACC,SAAS;IACnB;IAEA,IAAI;QACF,IAAI,CAAC,IAAI,CAACC,MAAM,EAAE;YAChB,IAAI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
+
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
|
|
@@ -0,0 +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: sql<number>`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,OAAOb,GACJc,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertPathToJSONTraversal.d.ts","sourceRoot":"","sources":["../../src/createJSONQuery/convertPathToJSONTraversal.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,qBAAsB,MAAM,EAAE,KAAG,MAQvE,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const convertPathToJSONTraversal = (incomingSegments)=>{
|
|
2
|
+
const segments = [
|
|
3
|
+
...incomingSegments
|
|
4
|
+
];
|
|
5
|
+
segments.shift();
|
|
6
|
+
return segments.reduce((res, segment)=>{
|
|
7
|
+
const formattedSegment = Number.isNaN(parseInt(segment)) ? `'${segment}'` : segment;
|
|
8
|
+
return `${res}->>${formattedSegment}`;
|
|
9
|
+
}, '');
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=convertPathToJSONTraversal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/createJSONQuery/convertPathToJSONTraversal.ts"],"sourcesContent":["export const convertPathToJSONTraversal = (incomingSegments: string[]): string => {\n const segments = [...incomingSegments]\n segments.shift()\n\n return segments.reduce((res, segment) => {\n const formattedSegment = Number.isNaN(parseInt(segment)) ? `'${segment}'` : segment\n return `${res}->>${formattedSegment}`\n }, '')\n}\n"],"names":["convertPathToJSONTraversal","incomingSegments","segments","shift","reduce","res","segment","formattedSegment","Number","isNaN","parseInt"],"mappings":"AAAA,OAAO,MAAMA,6BAA6B,CAACC;IACzC,MAAMC,WAAW;WAAID;KAAiB;IACtCC,SAASC,KAAK;IAEd,OAAOD,SAASE,MAAM,CAAC,CAACC,KAAKC;QAC3B,MAAMC,mBAAmBC,OAAOC,KAAK,CAACC,SAASJ,YAAY,CAAC,CAAC,EAAEA,QAAQ,CAAC,CAAC,GAAGA;QAC5E,OAAO,CAAC,EAAED,IAAI,GAAG,EAAEE,iBAAiB,CAAC;IACvC,GAAG;AACL,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/createJSONQuery/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAmEpE,eAAO,MAAM,eAAe,4DAMzB,mBAAmB,KAAG,MAYxB,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const fromArray = ({ isRoot, operator, pathSegments, table, treatAsArray, value })=>{
|
|
2
|
+
const newPathSegments = pathSegments.slice(1);
|
|
3
|
+
const alias = `${pathSegments[isRoot ? 0 : 1]}_alias_${newPathSegments.length}`;
|
|
4
|
+
return `EXISTS (
|
|
5
|
+
SELECT 1
|
|
6
|
+
FROM json_each(${table}.${pathSegments[0]}) AS ${alias}
|
|
7
|
+
WHERE ${createJSONQuery({
|
|
8
|
+
operator,
|
|
9
|
+
pathSegments: newPathSegments,
|
|
10
|
+
table: alias,
|
|
11
|
+
treatAsArray,
|
|
12
|
+
value
|
|
13
|
+
})}
|
|
14
|
+
)`;
|
|
15
|
+
};
|
|
16
|
+
const createConstraint = ({ alias, operator, pathSegments, value })=>{
|
|
17
|
+
const newAlias = `${pathSegments[0]}_alias_${pathSegments.length - 1}`;
|
|
18
|
+
let formattedValue = value;
|
|
19
|
+
let formattedOperator = operator;
|
|
20
|
+
if ([
|
|
21
|
+
'contains',
|
|
22
|
+
'like'
|
|
23
|
+
].includes(operator)) {
|
|
24
|
+
formattedOperator = 'like';
|
|
25
|
+
formattedValue = `%${value}%`;
|
|
26
|
+
} else if (operator === 'equals') {
|
|
27
|
+
formattedOperator = '=';
|
|
28
|
+
}
|
|
29
|
+
return `EXISTS (
|
|
30
|
+
SELECT 1
|
|
31
|
+
FROM json_each(${alias}.value -> '${pathSegments[0]}') AS ${newAlias}
|
|
32
|
+
WHERE ${newAlias}.value ->> '${pathSegments[1]}' ${formattedOperator} '${formattedValue}'
|
|
33
|
+
)`;
|
|
34
|
+
};
|
|
35
|
+
export const createJSONQuery = ({ operator, pathSegments, table, treatAsArray, value })=>{
|
|
36
|
+
if (treatAsArray.includes(pathSegments[1])) {
|
|
37
|
+
return fromArray({
|
|
38
|
+
operator,
|
|
39
|
+
pathSegments,
|
|
40
|
+
table,
|
|
41
|
+
treatAsArray,
|
|
42
|
+
value
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return createConstraint({
|
|
46
|
+
alias: table,
|
|
47
|
+
operator,
|
|
48
|
+
pathSegments,
|
|
49
|
+
treatAsArray,
|
|
50
|
+
value
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/createJSONQuery/index.ts"],"sourcesContent":["import type { CreateJSONQueryArgs } from '@payloadcms/drizzle/types'\n\ntype FromArrayArgs = {\n isRoot?: true\n operator: string\n pathSegments: string[]\n table: string\n treatAsArray?: string[]\n value: boolean | number | string\n}\n\nconst fromArray = ({\n isRoot,\n operator,\n pathSegments,\n table,\n treatAsArray,\n value,\n}: FromArrayArgs) => {\n const newPathSegments = pathSegments.slice(1)\n const alias = `${pathSegments[isRoot ? 0 : 1]}_alias_${newPathSegments.length}`\n\n return `EXISTS (\n SELECT 1\n FROM json_each(${table}.${pathSegments[0]}) AS ${alias}\n WHERE ${createJSONQuery({\n operator,\n pathSegments: newPathSegments,\n table: alias,\n treatAsArray,\n value,\n })}\n )`\n}\n\ntype CreateConstraintArgs = {\n alias?: string\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n value: boolean | number | string\n}\n\nconst createConstraint = ({\n alias,\n operator,\n pathSegments,\n value,\n}: CreateConstraintArgs): string => {\n const newAlias = `${pathSegments[0]}_alias_${pathSegments.length - 1}`\n let formattedValue = value\n let formattedOperator = operator\n\n if (['contains', 'like'].includes(operator)) {\n formattedOperator = 'like'\n formattedValue = `%${value}%`\n } else if (operator === 'equals') {\n formattedOperator = '='\n }\n\n return `EXISTS (\n SELECT 1\n FROM json_each(${alias}.value -> '${pathSegments[0]}') AS ${newAlias}\n WHERE ${newAlias}.value ->> '${pathSegments[1]}' ${formattedOperator} '${formattedValue}'\n )`\n}\n\nexport const createJSONQuery = ({\n operator,\n pathSegments,\n table,\n treatAsArray,\n value,\n}: CreateJSONQueryArgs): string => {\n if (treatAsArray.includes(pathSegments[1])) {\n return fromArray({\n operator,\n pathSegments,\n table,\n treatAsArray,\n value,\n })\n }\n\n return createConstraint({ alias: table, operator, pathSegments, treatAsArray, value })\n}\n"],"names":["fromArray","isRoot","operator","pathSegments","table","treatAsArray","value","newPathSegments","slice","alias","length","createJSONQuery","createConstraint","newAlias","formattedValue","formattedOperator","includes"],"mappings":"AAWA,MAAMA,YAAY,CAAC,EACjBC,MAAM,EACNC,QAAQ,EACRC,YAAY,EACZC,KAAK,EACLC,YAAY,EACZC,KAAK,EACS;IACd,MAAMC,kBAA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cC;IAAM;AACtF,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../src/createMigration.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAgB9C,eAAO,MAAM,eAAe,EAAE,eAkG7B,CAAA"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax, no-await-in-loop */ import fs from 'fs';
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { getPredefinedMigration } from 'payload';
|
|
5
|
+
import prompts from 'prompts';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import { defaultDrizzleSnapshot } from './defaultSnapshot.js';
|
|
8
|
+
import { getMigrationTemplate } from './getMigrationTemplate.js';
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
export const createMigration = async function createMigration({ file, forceAcceptWarning, migrationName, payload }) {
|
|
11
|
+
const filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const dirname = path.dirname(filename);
|
|
13
|
+
const dir = payload.db.migrationDir;
|
|
14
|
+
if (!fs.existsSync(dir)) {
|
|
15
|
+
fs.mkdirSync(dir);
|
|
16
|
+
}
|
|
17
|
+
const { generateSQLiteDrizzleJson, generateSQLiteMigration } = require('drizzle-kit/payload');
|
|
18
|
+
const drizzleJsonAfter = await generateSQLiteDrizzleJson(this.schema);
|
|
19
|
+
const [yyymmdd, hhmmss] = new Date().toISOString().split('T');
|
|
20
|
+
const formattedDate = yyymmdd.replace(/\D/g, '');
|
|
21
|
+
const formattedTime = hhmmss.split('.')[0].replace(/\D/g, '');
|
|
22
|
+
let imports = '';
|
|
23
|
+
let downSQL;
|
|
24
|
+
let upSQL;
|
|
25
|
+
({ downSQL, imports, upSQL } = await getPredefinedMigration({
|
|
26
|
+
dirname,
|
|
27
|
+
file,
|
|
28
|
+
migrationName,
|
|
29
|
+
payload
|
|
30
|
+
}));
|
|
31
|
+
const timestamp = `${formattedDate}_${formattedTime}`;
|
|
32
|
+
const name = migrationName || file?.split('/').slice(2).join('/');
|
|
33
|
+
const fileName = `${timestamp}${name ? `_${name.replace(/\W/g, '_')}` : ''}`;
|
|
34
|
+
const filePath = `${dir}/${fileName}`;
|
|
35
|
+
let drizzleJsonBefore = defaultDrizzleSnapshot;
|
|
36
|
+
if (!upSQL) {
|
|
37
|
+
// Get latest migration snapshot
|
|
38
|
+
const latestSnapshot = fs.readdirSync(dir).filter((file)=>file.endsWith('.json')).sort().reverse()?.[0];
|
|
39
|
+
if (latestSnapshot) {
|
|
40
|
+
drizzleJsonBefore = JSON.parse(fs.readFileSync(`${dir}/${latestSnapshot}`, 'utf8'));
|
|
41
|
+
}
|
|
42
|
+
const sqlStatementsUp = await generateSQLiteMigration(drizzleJsonBefore, drizzleJsonAfter);
|
|
43
|
+
const sqlStatementsDown = await generateSQLiteMigration(drizzleJsonAfter, drizzleJsonBefore);
|
|
44
|
+
// need to create tables as separate statements
|
|
45
|
+
const sqlExecute = 'await db.run(sql`';
|
|
46
|
+
if (sqlStatementsUp?.length) {
|
|
47
|
+
upSQL = sqlStatementsUp.map((statement)=>`${sqlExecute}${statement?.replaceAll('`', '\\`')}\`)`).join('\n');
|
|
48
|
+
}
|
|
49
|
+
if (sqlStatementsDown?.length) {
|
|
50
|
+
downSQL = sqlStatementsDown.map((statement)=>`${sqlExecute}${statement?.replaceAll('`', '\\`')}\`)`).join('\n');
|
|
51
|
+
}
|
|
52
|
+
if (!upSQL?.length && !downSQL?.length && !forceAcceptWarning) {
|
|
53
|
+
const { confirm: shouldCreateBlankMigration } = await prompts({
|
|
54
|
+
name: 'confirm',
|
|
55
|
+
type: 'confirm',
|
|
56
|
+
initial: false,
|
|
57
|
+
message: 'No schema changes detected. Would you like to create a blank migration file?'
|
|
58
|
+
}, {
|
|
59
|
+
onCancel: ()=>{
|
|
60
|
+
process.exit(0);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
if (!shouldCreateBlankMigration) {
|
|
64
|
+
process.exit(0);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// write schema
|
|
68
|
+
fs.writeFileSync(`${filePath}.json`, JSON.stringify(drizzleJsonAfter, null, 2));
|
|
69
|
+
}
|
|
70
|
+
// write migration
|
|
71
|
+
fs.writeFileSync(`${filePath}.ts`, getMigrationTemplate({
|
|
72
|
+
downSQL: downSQL || ` // Migration code`,
|
|
73
|
+
imports,
|
|
74
|
+
upSQL: upSQL || ` // Migration code`
|
|
75
|
+
}));
|
|
76
|
+
payload.logger.info({
|
|
77
|
+
msg: `Migration created at ${filePath}.ts`
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=createMigration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/createMigration.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type { DrizzleSnapshotJSON } from 'drizzle-kit/payload'\nimport type { CreateMigration } from 'payload'\n\nimport fs from 'fs'\nimport { createRequire } from 'module'\nimport path from 'path'\nimport { getPredefinedMigration } from 'payload'\nimport prompts from 'prompts'\nimport { fileURLToPath } from 'url'\n\nimport type { SQLiteAdapter } from './types.js'\n\nimport { defaultDrizzleSnapshot } from './defaultSnapshot.js'\nimport { getMigrationTemplate } from './getMigrationTemplate.js'\n\nconst require = createRequire(import.meta.url)\n\nexport const createMigration: CreateMigration = async function createMigration(\n this: SQLiteAdapter,\n { file, forceAcceptWarning, migrationName, payload },\n) {\n const filename = fileURLToPath(import.meta.url)\n const dirname = path.dirname(filename)\n const dir = payload.db.migrationDir\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir)\n }\n const { generateSQLiteDrizzleJson, generateSQLiteMigration } = require('drizzle-kit/payload')\n const drizzleJsonAfter = await generateSQLiteDrizzleJson(this.schema)\n const [yyymmdd, hhmmss] = new Date().toISOString().split('T')\n const formattedDate = yyymmdd.replace(/\\D/g, '')\n const formattedTime = hhmmss.split('.')[0].replace(/\\D/g, '')\n let imports: string = ''\n let downSQL: string\n let upSQL: string\n ;({ downSQL, imports, upSQL } = await getPredefinedMigration({\n dirname,\n file,\n migrationName,\n payload,\n }))\n\n const timestamp = `${formattedDate}_${formattedTime}`\n\n const name = migrationName || file?.split('/').slice(2).join('/')\n const fileName = `${timestamp}${name ? `_${name.replace(/\\W/g, '_')}` : ''}`\n\n const filePath = `${dir}/${fileName}`\n\n let drizzleJsonBefore = defaultDrizzleSnapshot as any\n\n if (!upSQL) {\n // Get latest migration snapshot\n const latestSnapshot = fs\n .readdirSync(dir)\n .filter((file) => file.endsWith('.json'))\n .sort()\n .reverse()?.[0]\n\n if (latestSnapshot) {\n drizzleJsonBefore = JSON.parse(\n fs.readFileSync(`${dir}/${latestSnapshot}`, 'utf8'),\n ) as DrizzleSnapshotJSON\n }\n\n const sqlStatementsUp = await generateSQLiteMigration(drizzleJsonBefore, drizzleJsonAfter)\n const sqlStatementsDown = await generateSQLiteMigration(drizzleJsonAfter, drizzleJsonBefore)\n // need to create tables as separate statements\n const sqlExecute = 'await db.run(sql`'\n\n if (sqlStatementsUp?.length) {\n upSQL = sqlStatementsUp\n .map((statement) => `${sqlExecute}${statement?.replaceAll('`', '\\\\`')}\\`)`)\n .join('\\n')\n }\n if (sqlStatementsDown?.length) {\n downSQL = sqlStatementsDown\n .map((statement) => `${sqlExecute}${statement?.replaceAll('`', '\\\\`')}\\`)`)\n .join('\\n')\n }\n\n if (!upSQL?.length && !downSQL?.length && !forceAcceptWarning) {\n const { confirm: shouldCreateBlankMigration } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message: 'No schema changes detected. Would you like to create a blank migration file?',\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!shouldCreateBlankMigration) {\n process.exit(0)\n }\n }\n\n // write schema\n fs.writeFileSync(`${filePath}.json`, JSON.stringify(drizzleJsonAfter, null, 2))\n }\n\n // write migration\n fs.writeFileSync(\n `${filePath}.ts`,\n getMigrationTemplate({\n downSQL: downSQL || ` // Migration code`,\n imports,\n upSQL: upSQL || ` // Migration code`,\n }),\n )\n payload.logger.info({ msg: `Migration created at ${filePath}.ts` })\n}\n"],"names":["fs","createRequire","path","getPredefinedMigration","prompts","fileURLToPath","defaultDrizzleSnapshot","getMigrationTemplate","require","url","createMigration","file","forceAcceptWarning","migrationName","payload","filename","dirname","dir","db","migrationDir","existsSync","mkdirSync","generateSQLiteDrizzleJson","generateSQLiteMigration","drizzleJsonAfter","schema","yyymmdd","hhmmss","Date","toISOString","split","formattedDate","replace","formattedTime","imports","downSQL","upSQL","timestamp","name","slice","join","fileName","filePath","drizzleJsonBefore","latestSnapshot","readdirSync","filter","endsWith","sort","reverse","JSON","parse","readFileSync","sqlStatementsUp","sqlStatementsDown","sqlExecute","length","map","statement","replaceAll","confirm","shouldCreateBlankMigration","type","initial","message","onCancel","process","exit","writeFileSync","stringify","logger","info","msg"],"mappings":"AAAA,yDAAyD,GAIzD,OAAOA,QAAQ,KAAI;AACnB,SAASC,aAAa,QAAQ,SAAQ;AACtC,OAAOC,UAAU,OAAM;AACvB,SAASC,sBAAsB,QAAQ,UAAS;AAChD,OAAOC,aAAa,UAAS;AAC7B,SAASC,aAAa,QAAQ,MAAK;AAInC,SAASC,sBAAsB,QAAQ,uBAAsB;AAC7D,SAASC,oBAAoB,QAAQ,4BAA2B;AAEhE,MAAMC,UAAUP,cAAc,YAAYQ,GAAG;AAE7C,OAAO,MAAMC,kBAAmC,eAAeA,gBAE7D,EAAEC,IAAI,EAAEC,kBAAkB,EAAEC,aAAa,EAAEC,OAAO,EAAE;IAEpD,MAAMC,WAAWV,cAAc,YAAYI,GAAG;IAC9C,MAAMO,UAAUd,KAAKc,OAAO,CAACD;IAC7B,MAAME,MAAMH,QAAQI,EAAE,CAACC,YAAY;IACnC,IAAI,CAACnB,GAAGoB,UAAU,C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|
|
1
|
+
{"version":3,"file":"defaultSnapshot.d.ts","sourceRoot":"","sources":["../src/defaultSnapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAA;AAEpE,eAAO,MAAM,sBAAsB,EAAE,yBAWpC,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const defaultDrizzleSnapshot = {
|
|
2
|
+
id: '00000000-0000-0000-0000-000000000000',
|
|
3
|
+
_meta: {
|
|
4
|
+
columns: {},
|
|
5
|
+
tables: {}
|
|
6
|
+
},
|
|
7
|
+
dialect: 'sqlite',
|
|
8
|
+
enums: {},
|
|
9
|
+
prevId: '00000000-0000-0000-0000-00000000000',
|
|
10
|
+
tables: {},
|
|
11
|
+
version: '6'
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=defaultSnapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/defaultSnapshot.ts"],"sourcesContent":["import type { DrizzleSQLiteSnapshotJSON } from 'drizzle-kit/payload'\n\nexport const defaultDrizzleSnapshot: DrizzleSQLiteSnapshotJSON = {\n id: '00000000-0000-0000-0000-000000000000',\n _meta: {\n columns: {},\n tables: {},\n },\n dialect: 'sqlite',\n enums: {},\n prevId: '00000000-0000-0000-0000-00000000000',\n tables: {},\n version: '6',\n}\n"],"names":["defaultDrizzleSnapshot","id","_meta","columns","tables","dialect","enums","prevId","version"],"mappings":"AAEA,OAAO,MAAMA,yBAAoD;IAC/DC,IAAI;IACJC,OAAO;QACLC,SAAS,CAAC;QACVC,QAAQ,CAAC;IACX;IACAC,SAAS;IACTC,OAAO,CAAC;IACRC,QAAQ;IACRH,QAAQ,CAAC;IACTI,SAAS;AACX,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteWhere.d.ts","sourceRoot":"","sources":["../src/deleteWhere.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,eAAO,MAAM,WAAW,EAAE,WAGzB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/deleteWhere.ts"],"sourcesContent":["import type { DeleteWhere } from './types.js'\n\nexport const deleteWhere: DeleteWhere = async function deleteWhere({ db, tableName, where }) {\n const table = this.tables[tableName]\n await db.delete(table).where(where)\n}\n"],"names":["deleteWhere","db","tableName","where","table","tables","delete"],"mappings":"AAEA,OAAO,MAAMA,cAA2B,eAAeA,YAAY,EAAEC,EAAE,EAAEC,SAAS,EAAEC,KAAK,EAAE;IACzF,MAAMC,QAAQ,IAAI,CAACC,MAAM,CAACH,UAAU;IACpC,MAAMD,GAAGK,MAAM,CAACF,OAAOD,KAAK,CAACA;AAC/B,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dropDatabase.d.ts","sourceRoot":"","sources":["../src/dropDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAiB9C,eAAO,MAAM,YAAY,EAAE,YAG1B,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const getTables = (adapter)=>{
|
|
2
|
+
return adapter.client.execute(`SELECT name
|
|
3
|
+
FROM sqlite_master
|
|
4
|
+
WHERE type = 'table'
|
|
5
|
+
AND name NOT LIKE 'sqlite_%';`);
|
|
6
|
+
};
|
|
7
|
+
const dropTables = (adapter, rows)=>{
|
|
8
|
+
const multi = `
|
|
9
|
+
PRAGMA foreign_keys = OFF;\n
|
|
10
|
+
${rows.map(({ name })=>`DROP TABLE IF EXISTS ${name}`).join(';\n ')};\n
|
|
11
|
+
PRAGMA foreign_keys = ON;`;
|
|
12
|
+
return adapter.client.executeMultiple(multi);
|
|
13
|
+
};
|
|
14
|
+
export const dropDatabase = async function dropDatabase({ adapter }) {
|
|
15
|
+
const result = await getTables(adapter);
|
|
16
|
+
await dropTables(adapter, result.rows);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=dropDatabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/dropDatabase.ts"],"sourcesContent":["import type { DropDatabase } from './types.js'\n\nconst getTables = (adapter) => {\n return adapter.client.execute(`SELECT name\n FROM sqlite_master\n WHERE type = 'table'\n AND name NOT LIKE 'sqlite_%';`)\n}\n\nconst dropTables = (adapter, rows) => {\n const multi = `\n PRAGMA foreign_keys = OFF;\\n\n ${rows.map(({ name }) => `DROP TABLE IF EXISTS ${name}`).join(';\\n ')};\\n\n PRAGMA foreign_keys = ON;`\n return adapter.client.executeMultiple(multi)\n}\n\nexport const dropDatabase: DropDatabase = async function dropDatabase({ adapter }) {\n const result = await getTables(adapter)\n await dropTables(adapter, result.rows)\n}\n"],"names":["getTables","adapter","client","execute","dropTables","rows","multi","map","name","join","executeMultiple","dropDatabase","result"],"mappings":"AAEA,MAAMA,YAAY,CAACC;IACjB,OAAOA,QAAQC,MAAM,CAACC,OAAO,CAAC,CAAC;;;gEAG+B,CAAC;AACjE;AAEA,MAAMC,aAAa,CAACH,SAASI;IAC3B,MAAMC,QAAQ,CAAC;;EAEf,EAAED,KAAKE,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAK,CAAC,qBAAqB,EAAEA,KAAK,CAAC,EAAEC,IAAI,CAAC,QAAQ;2BAC7C,CAAC;IAC1B,OAAOR,QAAQC,MAAM,CAACQ,eAAe,CAACJ;AACxC;AAEA,OAAO,MAAMK,eAA6B,eAAeA,aAAa,EAAEV,OAAO,EAAE;IAC/E,MAAMW,SAAS,MAAMZ,UAAUC;IAC/B,MAAMG,WAAWH,SAASW,OAAOP,IAAI;AACvC,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../src/execute.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC,eAAO,MAAM,OAAO,EAAE,OAAO,CAAC,GAAG,CAUhC,CAAA"}
|
package/dist/execute.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
export const execute = function execute({ db, drizzle, raw, sql: statement }) {
|
|
3
|
+
const executeFrom = db ?? drizzle;
|
|
4
|
+
if (raw) {
|
|
5
|
+
const result = executeFrom.run(sql.raw(raw));
|
|
6
|
+
return result;
|
|
7
|
+
} else {
|
|
8
|
+
const result = executeFrom.run(statement);
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=execute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/execute.ts"],"sourcesContent":["import { sql } from 'drizzle-orm'\n\nimport type { Execute } from './types.js'\n\nexport const execute: Execute<any> = function execute({ db, drizzle, raw, sql: statement }) {\n const executeFrom = db ?? drizzle\n\n if (raw) {\n const result = executeFrom.run(sql.raw(raw))\n return result\n } else {\n const result = executeFrom.run(statement)\n return result\n }\n}\n"],"names":["sql","execute","db","drizzle","raw","statement","executeFrom","result","run"],"mappings":"AAAA,SAASA,GAAG,QAAQ,cAAa;AAIjC,OAAO,MAAMC,UAAwB,SAASA,QAAQ,EAAEC,EAAE,EAAEC,OAAO,EAAEC,GAAG,EAAEJ,KAAKK,SAAS,EAAE;IACxF,MAAMC,cAAcJ,MAAMC;IAE1B,IAAIC,KAAK;QACP,MAAMG,SAASD,YAAYE,GAAG,CAACR,IAAII,GAAG,CAACA;QACvC,OAAOG;IACT,OAAO;QACL,MAAMA,SAASD,YAAYE,GAAG,CAACH;QAC/B,OAAOE;IACT;AACF,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateDrizzleJSON.d.ts","sourceRoot":"","sources":["../src/generateDrizzleJSON.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C,eAAO,MAAM,mBAAmB,EAAE,aAAa,CAAC,qBAAqB,CAKlE,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
export const generateDrizzleJSON = function generateDrizzleJSON({ schema }) {
|
|
4
|
+
const { generateSQLiteDrizzleJson } = require('drizzle-kit/payload');
|
|
5
|
+
return generateSQLiteDrizzleJson(schema);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=generateDrizzleJSON.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generateDrizzleJSON.ts"],"sourcesContent":["import { createRequire } from 'module'\nconst require = createRequire(import.meta.url)\n\nimport type { SQLiteAdapter } from './types.js'\n\nexport const generateDrizzleJSON: SQLiteAdapter['generateDrizzleJSON'] =\n function generateDrizzleJSON({ schema }) {\n const { generateSQLiteDrizzleJson } = require('drizzle-kit/payload')\n\n return generateSQLiteDrizzleJson(schema)\n }\n"],"names":["createRequire","require","url","generateDrizzleJSON","schema","generateSQLiteDrizzleJson"],"mappings":"AAAA,SAASA,aAAa,QAAQ,SAAQ;AACtC,MAAMC,UAAUD,cAAc,YAAYE,GAAG;AAI7C,OAAO,MAAMC,sBACX,SAASA,oBAAoB,EAAEC,MAAM,EAAE;IACrC,MAAM,EAAEC,yBAAyB,EAAE,GAAGJ,QAAQ;IAE9C,OAAOI,0BAA0BD;AACnC,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMigrationTemplate.d.ts","sourceRoot":"","sources":["../src/getMigrationTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,eAAO,MAAM,oBAAoB,iCAI9B,qBAAqB,KAAG,MAS1B,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const getMigrationTemplate = ({ downSQL, imports, upSQL })=>`import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-sqlite'
|
|
2
|
+
${imports ? `${imports}\n` : ''}
|
|
3
|
+
export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
|
|
4
|
+
${upSQL}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
|
|
8
|
+
${downSQL}
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=getMigrationTemplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/getMigrationTemplate.ts"],"sourcesContent":["import type { MigrationTemplateArgs } from 'payload'\n\nexport const getMigrationTemplate = ({\n downSQL,\n imports,\n upSQL,\n}: MigrationTemplateArgs): string => `import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-sqlite'\n${imports ? `${imports}\\n` : ''}\nexport async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {\n${upSQL}\n}\n\nexport async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {\n${downSQL}\n}\n`\n"],"names":["getMigrationTemplate","downSQL","imports","upSQL"],"mappings":"AAEA,OAAO,MAAMA,uBAAuB,CAAC,EACnCC,OAAO,EACPC,OAAO,EACPC,KAAK,EACiB,GAAa,CAAC;AACtC,EAAED,UAAU,CAAC,EAAEA,QAAQ,EAAE,CAAC,GAAG,GAAG;;AAEhC,EAAEC,MAAM;;;;AAIR,EAAEF,QAAQ;;AAEV,CAAC,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DatabaseAdapterObj } from 'payload';
|
|
2
|
+
import type { Args, SQLiteAdapter } from './types.js';
|
|
3
|
+
export type { MigrateDownArgs, MigrateUpArgs } from './types.js';
|
|
4
|
+
export { sql } from 'drizzle-orm';
|
|
5
|
+
export declare function sqliteAdapter(args: Args): DatabaseAdapterObj<SQLiteAdapter>;
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAW,MAAM,SAAS,CAAA;AAmC1D,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAiBrD,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,CAqG3E"}
|