create-absolutejs 0.3.14 → 0.3.15

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.
@@ -34,6 +34,11 @@ declare const driverConfigurations: {
34
34
  readonly importLines: "import { ConnectionPool } from 'mssql'";
35
35
  readonly queries: QueryOperations;
36
36
  };
37
+ readonly 'mysql:drizzle:local': {
38
+ readonly dbType: "MySql2Database<SchemaType>";
39
+ readonly importLines: "\nimport { eq } from 'drizzle-orm'\nimport { MySql2Database } from 'drizzle-orm/mysql2'\nimport { schema, type SchemaType } from '../../../db/schema'";
40
+ readonly queries: QueryOperations;
41
+ };
37
42
  readonly 'mysql:sql:local': {
38
43
  readonly dbType: "Pool";
39
44
  readonly handlerTypes: HandlerType;
@@ -235,6 +235,39 @@ const mysqlHandlerTypes = {
235
235
  metadata: string;
236
236
  }`
237
237
  };
238
+ const mysqlDrizzleQueryOperations = {
239
+ insertHistory: `const [row] = await db
240
+ .insert(schema.countHistory)
241
+ .values({ count })
242
+ .$returningId();
243
+
244
+ if (!row) throw new Error('insert failed: no uid returned');
245
+ const { uid } = row;
246
+
247
+ const [newHistory] = await db
248
+ .select()
249
+ .from(schema.countHistory)
250
+ .where(eq(schema.countHistory.uid, uid));
251
+
252
+ return newHistory;`,
253
+ insertUser: `const [row] = await db
254
+ .insert(schema.users)
255
+ .values({ auth_sub: authSub, metadata: userIdentity })
256
+ .$returningId();
257
+
258
+ if (!row) throw new Error('insert failed: no uid returned');
259
+ const { uid } = row;
260
+
261
+ const [newUser] = await db
262
+ .select()
263
+ .from(schema.users)
264
+ .where(eq(schema.users.uid, uid));
265
+
266
+ if (!newUser) throw new Error('Failed to create user');
267
+ return newUser;`,
268
+ selectHistory: drizzleQueryOperations.selectHistory,
269
+ selectUser: drizzleQueryOperations.selectUser
270
+ };
238
271
  const driverConfigurations = {
239
272
  'cockroachdb:sql:local': {
240
273
  dbType: 'Pool',
@@ -261,6 +294,14 @@ const driverConfigurations = {
261
294
  importLines: `import { ConnectionPool } from 'mssql'`,
262
295
  queries: mssqlSqlQueryOperations
263
296
  },
297
+ 'mysql:drizzle:local': {
298
+ dbType: 'MySql2Database<SchemaType>',
299
+ importLines: `
300
+ import { eq } from 'drizzle-orm'
301
+ import { MySql2Database } from 'drizzle-orm/mysql2'
302
+ import { schema, type SchemaType } from '../../../db/schema'`,
303
+ queries: mysqlDrizzleQueryOperations
304
+ },
264
305
  'mysql:sql:local': {
265
306
  dbType: 'Pool',
266
307
  handlerTypes: mysqlHandlerTypes,
@@ -51,14 +51,20 @@ export const generateDBBlock = ({ databaseEngine, orm, databaseHost }) => {
51
51
  return '';
52
52
  return `
53
53
  const db = ${hostCfg.expr}
54
- ${hostCfg.connect ? 'await db.connect();\n' : ''}
55
- `;
54
+ ${hostCfg.connect ? 'await db.connect();\n' : ''}`;
56
55
  }
57
56
  if (!drizzleDialectSet.has(databaseEngine))
58
57
  return '';
59
58
  const expr = engineGroup[hostKey]?.expr ?? remoteDrizzleInit[hostKey];
60
59
  if (!expr)
61
60
  return '';
61
+ if (databaseEngine === 'mysql') {
62
+ const mode = databaseHost === 'planetscale' ? 'planetscale' : 'default';
63
+ return `
64
+ const sql = ${expr}
65
+ const db = drizzle(sql, { schema, mode: '${mode}' })
66
+ `;
67
+ }
62
68
  return `
63
69
  const sql = ${expr}
64
70
  const db = drizzle(sql, { schema })
@@ -66,10 +66,17 @@ export const generateImportsBlock = ({ backendDirectory, deps, flags, orm, authP
66
66
  `import { getEnv } from '@absolutejs/absolute'`
67
67
  ]
68
68
  : [`import { Database } from 'bun:sqlite'`]));
69
- if (noOrm && databaseEngine === 'mysql') {
70
- rawImports.push(...(isRemoteHost
71
- ? connectorImports[databaseHost]
72
- : [`import { createPool } from 'mysql2/promise'`]), `import { getEnv } from '@absolutejs/absolute'`);
69
+ if (databaseEngine === 'mysql' && isRemoteHost) {
70
+ rawImports.push(...connectorImports[databaseHost]);
71
+ }
72
+ if (databaseEngine === 'mysql' && !isRemoteHost) {
73
+ rawImports.push("import { createPool } from 'mysql2/promise'");
74
+ }
75
+ if (databaseEngine === 'mysql' && orm === 'drizzle') {
76
+ rawImports.push("import { drizzle } from 'drizzle-orm/mysql2'");
77
+ }
78
+ if (databaseEngine === 'mysql') {
79
+ rawImports.push("import { getEnv } from '@absolutejs/absolute'");
73
80
  }
74
81
  if (noOrm && databaseEngine === 'postgresql')
75
82
  rawImports.push(...(isRemoteHost
package/package.json CHANGED
@@ -47,5 +47,5 @@
47
47
  "typecheck": "bun run tsc --noEmit"
48
48
  },
49
49
  "type": "module",
50
- "version": "0.3.14"
50
+ "version": "0.3.15"
51
51
  }