Skip to content

Refactor database conditionals for readability#13

Merged
absolutejs merged 5 commits intomainfrom
fix/code-cleanup
Nov 24, 2025
Merged

Refactor database conditionals for readability#13
absolutejs merged 5 commits intomainfrom
fix/code-cleanup

Conversation

@bnziv
Copy link
Copy Markdown
Collaborator

@bnziv bnziv commented Nov 23, 2025

Summary by CodeRabbit

  • New Features

    • Added MariaDB dialect and local Drizzle driver; automated, engine-driven DB scripts (db:up/down/reset, engine-specific tasks) and unified container command handling.
  • Bug Fixes

    • Fixed MSSQL init wait-command quoting and removed duplicate DB config entries.
  • Refactor

    • Consolidated DB setup, container templates, import assembly, and initialization logic for a simpler, engine-agnostic flow; simplified Drizzle vs non-Drizzle paths.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 23, 2025

Walkthrough

Consolidates DB/npm-script generation into engine-driven mappings with an isLocal flag; introduces a typed top-level command for docker templates; adds MariaDB Drizzle dialect/driver entries; centralizes import assembly via maps; and simplifies DB connection emission for Drizzle and non-Drizzle paths. (38 words)

Changes

Cohort / File(s) Change Summary
Package JSON script generation
src/generators/configurations/generatePackageJson.ts
Add dbScripts mapping per engine (clientCmd, waitCmd); introduce isLocal; replace per-engine npm-script branches with unified engine-driven emission (db:up, postdb:up, db:down, db:reset, db:<engine>); adjust dependency handling (e.g., add @types/mssql for local MSSQL).
Docker init templates & container generation
src/generators/db/dockerInitTemplates.ts, src/generators/db/generateDockerContainer.ts
MSSQL wait command quoting changed to use double quotes; introduce DatabaseTemplate interface and top-level optional command in templates; move per-engine command handling to top-level and conditionally render command block in generated YAML.
Drizzle dialects & handler templates
src/generators/db/generateDrizzleSchema.ts, src/generators/db/handlerTemplates.ts
Add mariadb dialect entry in DIALECTS; relocate/add MariaDB Drizzle local driver configuration under driverConfigurations; remove duplicate mariadb block and sqlite-specific Drizzle block.
Project DB generation & imports
src/generators/project/generateDBBlock.ts, src/generators/project/generateImportsBlock.ts
Simplify non-Drizzle DB emission to a single-line const db = ... when host config exists; change mysql/mariadb Drizzle pool/init semantics; replace ad-hoc import pushes with ormImports, ormDatabaseImports, and noOrmImports maps and isDrizzleDialect checks to centralize import assembly.
Stylistic / minor
src/generators/configurations/...
Reordered import (computeFlags moved after initTemplates) — stylistic only.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor CLI as Generator CLI
  participant GenPkg as generatePackageJson
  participant GenDocker as generateDockerContainer
  participant GenDB as generateDBBlock
  participant GenImport as generateImportsBlock

  CLI->>GenPkg: provide config (engine, host, orm, flags)
  alt isLocal && engine supports docker
    GenPkg-->>CLI: emit unified scripts (db:up, postdb:up, db:down, db:reset, db:<engine>)
  else sqlite/remote/unsupported
    GenPkg-->>CLI: emit sqlite-specific or no-local scripts
  end

  CLI->>GenDocker: request container templates
  GenDocker-->>CLI: return templates {image, port, env, volumePath, optional command}

  CLI->>GenDB: request DB snippet (orm, engine, host)
  alt orm == drizzle
    GenDB-->>CLI: emit drizzle connection (createPool for mysql/mariadb or SQL/driver expr)
  else
    GenDB-->>CLI: emit single-line `const db = ...` or empty
  end

  CLI->>GenImport: request imports (orm, engine, host, isDrizzleDialect)
  GenImport-->>CLI: assemble imports via ormImports / ormDatabaseImports / noOrmImports maps
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Focus areas:
    • src/generators/configurations/generatePackageJson.ts — verify dbScripts values, dockerPrefixing, isLocal branching and npm-script naming.
    • src/generators/project/generateImportsBlock.ts — ensure import maps cover prior conditional cases (remote/local/dialect/auth).
    • src/generators/project/generateDBBlock.ts — confirm changed connection expressions and Drizzle mysql/mariadb pool semantics.
    • src/generators/db/generateDockerContainer.ts & src/generators/db/dockerInitTemplates.ts — check typed templates, conditional command rendering, and MSSQL wait quoting.

Possibly related PRs

Suggested reviewers

  • absolutejs

Poem

🐇 I hopped through mappings, scripts neat and trim,
Maria joined schemas, containers hum on cue,
One-line DBs, commands lifted into place,
Imports all aligned, tidy as a garden row,
Carrots for CI and a quiet, cozy build-night. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Refactor database conditionals for readability' accurately describes the main objectives of the changeset, which involves consolidating and reorganizing database-related logic across multiple files for improved maintainability.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/code-cleanup

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 151f098 and 0678b8d.

📒 Files selected for processing (7)
  • src/generators/configurations/generatePackageJson.ts (3 hunks)
  • src/generators/db/dockerInitTemplates.ts (1 hunks)
  • src/generators/db/generateDockerContainer.ts (9 hunks)
  • src/generators/db/generateDrizzleSchema.ts (3 hunks)
  • src/generators/db/handlerTemplates.ts (1 hunks)
  • src/generators/project/generateDBBlock.ts (3 hunks)
  • src/generators/project/generateImportsBlock.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/generators/db/handlerTemplates.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/generators/db/dockerInitTemplates.ts
  • src/generators/db/generateDrizzleSchema.ts
🧰 Additional context used
🧬 Code graph analysis (3)
src/generators/project/generateImportsBlock.ts (1)
src/typeGuards.ts (1)
  • isDrizzleDialect (27-30)
src/generators/db/generateDockerContainer.ts (1)
src/types.ts (1)
  • DatabaseEngine (45-47)
src/generators/configurations/generatePackageJson.ts (1)
src/generators/db/dockerInitTemplates.ts (1)
  • initTemplates (112-141)
🔇 Additional comments (6)
src/generators/db/generateDockerContainer.ts (2)

3-93: DatabaseTemplate + templates map are coherent and type-safe

Using Exclude<DatabaseEngine, 'none' | 'sqlite' | undefined> for the templates keys nicely guarantees every real engine has a template, and making command optional avoids the previous empty-string noise. The per-engine image/port/env/volumePath entries all look internally consistent.


95-126: Conditional command rendering now produces valid compose YAML

The commandLines block is correctly indented at the service level and only emitted when defined, so the generated docker-compose snippet keeps command as a sibling of ports/volumes without disturbing the layout when absent.

src/generators/project/generateImportsBlock.ts (2)

102-110: Drizzle base imports are centralized and conditionally gated well

The ormImports.drizzle array nicely bundles shared drizzle imports, and the conditions for getEnv (skip local sqlite) and schema/User when authProvider === 'absoluteAuth' keep the generated code focused and avoid obvious unused imports.


141-181: Map-driven no-ORM imports improve readability and keep host logic localized

The noOrmImports map plus the if (noOrm && hasDatabase && noOrmImports[databaseEngine]) guard is a clear improvement over scattered conditionals: local vs remote host handling for mysql/postgresql/sqlite is now expressed in one place and aligns with the connection strategies in generateDBBlock.

Also applies to: 198-200

src/generators/project/generateDBBlock.ts (1)

6-38: Connection map adjustments align non-ORM paths and fix MongoClient typo

Updating mariadb.none/mysql.none to use new SQL(getEnv("DATABASE_URL")) and fixing the MongoClient expression bring the non-drizzle paths in line with the imports from generateImportsBlock and remove the stray brace bug for MongoDB.

src/generators/configurations/generatePackageJson.ts (1)

32-55: DB script and dependency gating are now centralized and align with local-only behavior

The dbScripts map plus the isLocal gate for generating db:* scripts and predev/postdev keeps all docker-related logic in one place and avoids sprinkling engine checks across the file. Likewise, adding mysql2 only for local drizzle MySQL/MariaDB, and scoping mssql/@types/mssql and sqlite CLI scripts to local setups, lines up with the intent that remote providers use their own connectors instead of mysql2/bun-specific clients.

Also applies to: 191-217, 219-236


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/generators/db/generateDockerContainer.ts (1)

4-88: Avoid emitting an empty command: in docker-compose for most engines

Right now command is set to '' for all engines except CockroachDB, but the compose template always emits:

command: ${command}

For those engines this becomes command: with an empty value, which can override the image’s default CMD and potentially prevent the DB from starting correctly. It’s safer to omit the command line entirely unless an override is required.

You can fix this by making the command line conditional, e.g.:

-const templates = {
-	cockroachdb: {
-		command: 'start-single-node --insecure',
+const templates = {
+	cockroachdb: {
+		command: 'start-single-node --insecure',
@@
-const { image, port, env, volumePath, command } = templates[databaseEngine];
+const { image, port, env, volumePath, command } = templates[databaseEngine];
+const commandLine = command ? `\n        command: ${command}` : '';
@@
-        ports:
-            - "${port}"
-        command: ${command}
-        volumes:
+        ports:
+            - "${port}"${commandLine}
+        volumes:
             - db_data:${volumePath}
🧹 Nitpick comments (3)
src/generators/configurations/generatePackageJson.ts (3)

32-54: Consider adding password environment variables for MySQL/MariaDB client commands.

The clientCmd for mysql and mariadb lacks the MYSQL_PWD=userpassword environment variable present in initTemplates.cli. When users run bun db:mysql or bun db:mariadb, they'll be prompted for a password, which may be unexpected since the docker container has a preset password.

Apply this diff to add the password environment variable:

 	mariadb: {
-		clientCmd: 'mariadb -h127.0.0.1 -u user database',
+		clientCmd: 'MYSQL_PWD=userpassword mariadb -h127.0.0.1 -u user database',
 		waitCmd: initTemplates.mariadb.wait
 	},
 	mysql: {
-		clientCmd: 'mysql -h127.0.0.1 -u user database',
+		clientCmd: 'MYSQL_PWD=userpassword mysql -h127.0.0.1 -u user database',
 		waitCmd: initTemplates.mysql.wait
 	},

202-202: Add runtime type guard for safer dbScripts access.

While the current logic ensures only engines present in dbScripts reach line 202, there's no type-level constraint. If a new database engine is added to the type system in the future without updating dbScripts, this will cause a runtime error.

Apply this diff to add a type guard:

 		} else {
+			if (!(databaseEngine in dbScripts)) {
+				throw new Error(
+					`Internal error: Database engine "${databaseEngine}" not supported in dbScripts`
+				);
+			}
 			const config = dbScripts[databaseEngine];

210-211: Consider adding -it flags for interactive database client scripts.

The generated db:<engine> scripts (e.g., db:mysql, db:postgresql) are likely intended for interactive shell access, but the docker compose exec command doesn't include -it flags for interactive terminal support. Users may experience issues with terminal input/output.

Apply this diff to add interactive flags:

 			scripts[`db:${databaseEngine}`] =
-				`${dockerPrefix} exec db bash -lc '${config.clientCmd}'`;
+				`${dockerPrefix} exec -it db bash -lc '${config.clientCmd}'`;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cf8e385 and 92da0f8.

📒 Files selected for processing (7)
  • src/generators/configurations/generatePackageJson.ts (3 hunks)
  • src/generators/db/dockerInitTemplates.ts (1 hunks)
  • src/generators/db/generateDockerContainer.ts (3 hunks)
  • src/generators/db/generateDrizzleSchema.ts (3 hunks)
  • src/generators/db/handlerTemplates.ts (1 hunks)
  • src/generators/project/generateDBBlock.ts (1 hunks)
  • src/generators/project/generateImportsBlock.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-22T04:55:44.009Z
Learnt from: bnziv
Repo: absolutejs/create-absolutejs PR: 11
File: src/generators/configurations/generateEnv.ts:17-17
Timestamp: 2025-11-22T04:55:44.009Z
Learning: The mssql npm package supports Windows-style connection string format (key=value pairs separated by semicolons) in addition to URI format. Connection strings like "Server=localhost,1433;Database=master;User Id=sa;Password=SApassword1;Encrypt=true;TrustServerCertificate=true" are valid for the mssql package.

Applied to files:

  • src/generators/db/dockerInitTemplates.ts
🧬 Code graph analysis (2)
src/generators/project/generateImportsBlock.ts (2)
src/typeGuards.ts (1)
  • isDrizzleDialect (27-30)
src/generators/db/scaffoldDatabase.ts (1)
  • ScaffoldDatabaseProps (27-107)
src/generators/configurations/generatePackageJson.ts (3)
src/generators/db/dockerInitTemplates.ts (1)
  • initTemplates (112-141)
src/generators/db/scaffoldDocker.ts (1)
  • ScaffoldDockerProps (20-56)
src/generators/db/scaffoldDatabase.ts (1)
  • ScaffoldDatabaseProps (27-107)
🔇 Additional comments (4)
src/generators/db/handlerTemplates.ts (1)

327-334: MariaDB drizzle driver configuration looks consistent

The new mariadb:drizzle:local entry matches the existing MySQL drizzle configuration (dbType, imports, and query operations) and should work correctly with drizzle-orm/mysql2 + MariaDB.

src/generators/db/generateDrizzleSchema.ts (1)

16-23: MariaDB dialect wiring is consistent with existing MySQL/singlestore behavior

The new mariadb entry in DIALECTS mirrors the MySQL setup (mysql-core builders), and the updated intBuilder/uidColumn conditions correctly treat MariaDB like MySQL/Singlestore for autoincrement integer PKs. This keeps schema generation consistent across these dialects.

Also applies to: 72-77, 111-121

src/generators/db/dockerInitTemplates.ts (1)

127-127: LGTM! Improved string readability.

The change from escaped single quotes to a double-quoted string with embedded single quotes improves readability without changing functionality.

src/generators/configurations/generatePackageJson.ts (1)

219-232: LGTM! Database-specific dependency logic is correct.

The conditional addition of mysql2 for MySQL/MariaDB with Drizzle and mssql packages for MS SQL Server is implemented correctly and maintains consistency with the previous logic.

Comment thread src/generators/project/generateImportsBlock.ts
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/generators/project/generateImportsBlock.ts (1)

130-130: Past critical issue resolved.

The missing closing backtick in the PostgreSQL drizzle import string has been fixed. The template literal is now properly terminated.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 92da0f8 and db793a5.

📒 Files selected for processing (2)
  • src/generators/project/generateDBBlock.ts (1 hunks)
  • src/generators/project/generateImportsBlock.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/generators/project/generateDBBlock.ts (4)
src/generators/db/generateDrizzleSchema.ts (1)
  • GenerateSchemaProps (66-163)
src/generators/db/generateHandlers.ts (1)
  • GenerateDBHandlersProps (9-28)
src/generators/db/scaffoldDatabase.ts (1)
  • ScaffoldDatabaseProps (27-107)
src/generators/configurations/generateEnv.ts (1)
  • GenerateEnvProps (23-44)
src/generators/project/generateImportsBlock.ts (3)
src/typeGuards.ts (1)
  • isDrizzleDialect (27-30)
src/generators/db/generateDrizzleSchema.ts (1)
  • GenerateSchemaProps (66-163)
src/generators/db/scaffoldDatabase.ts (1)
  • ScaffoldDatabaseProps (27-107)
🔇 Additional comments (1)
src/generators/project/generateImportsBlock.ts (1)

102-202: LGTM: Well-structured refactor with clear separation of concerns.

The introduction of structured import maps (ormImports, ormDatabaseImports, noOrmImports) significantly improves maintainability over the previous ad-hoc approach. The conditional assembly logic (lines 185-202) correctly:

  • Pushes base ORM imports for drizzle
  • Adds remote connector/dialect imports when isRemoteHost
  • Includes database-specific imports when isDrizzleDialect(databaseEngine) is true
  • Falls back to noOrmImports for no-ORM configurations

The alignment between these imports and the usage in generateDBBlock.ts appears correct for all database engine and host combinations.

Comment thread src/generators/project/generateDBBlock.ts
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/generators/configurations/generatePackageJson.ts (1)

190-233: DB scripts guard looks sane, but indexing into dbScripts could be safer

The new guard around DB script generation:

if (
  (!databaseHost || databaseHost === 'none') &&
  databaseEngine !== undefined &&
  databaseEngine !== 'none' &&
  databaseEngine !== 'mongodb' &&
  databaseEngine !== 'singlestore' &&
  databaseEngine !== 'gel'
) {
  
}

nicely confines docker‑based scripts to local, SQL‑style engines and keeps sqlite in an explicit branch, which improves readability.

Inside the else branch you rely on:

const config = dbScripts[databaseEngine];

This is correct for the current union (cockroachdb, mariadb, mssql, mysql, postgresql) plus sqlite handled above, but it depends on CreateConfiguration['databaseEngine'] staying in sync with keyof typeof dbScripts and the exclusion list. A future engine added to the union but not to dbScripts/exclusions will yield config as undefined at runtime.

Consider tightening this a bit by either:

  • Typing databaseEngine as keyof typeof dbScripts | 'sqlite' | 'mongodb' | 'singlestore' | 'gel' | 'none', or
  • Adding a small runtime guard:
const config = dbScripts[databaseEngine as keyof typeof dbScripts];
if (!config) {
  throw new Error(`Unsupported databaseEngine for db scripts: ${databaseEngine}`);
}

to fail fast rather than producing a cryptic error if things drift.

Otherwise, the consolidated scripts (db:up, postdb:up, db:down, db:reset, db:<engine>, plus pre/post dev hooks) and the conditional mysql2/mssql dependencies look consistent and easier to follow than the engine‑specific branches they replace.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db793a5 and 616ccda.

📒 Files selected for processing (1)
  • src/generators/configurations/generatePackageJson.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/generators/configurations/generatePackageJson.ts (1)
src/generators/db/dockerInitTemplates.ts (1)
  • initTemplates (112-141)

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/generators/project/generateDBBlock.ts (1)

77-77: Minor: expr retrieved but unused for mysql/mariadb in Drizzle path.

Line 77 retrieves expr from connectionMap[databaseEngine][hostKey], which for mysql.none or mariadb.none evaluates to new SQL(getEnv("DATABASE_URL")) (from lines 14, 23). However, the mysql/mariadb block (lines 80-90) ignores this expr and hardcodes createPool(getEnv("DATABASE_URL")) on line 87. The expr variable is only used in the fallback block (lines 92-95) for other database engines.

Consider refactoring to avoid the unused retrieval by moving line 77 inside the final else block, or document why different connection types are needed for Drizzle mysql/mariadb vs non-Drizzle.

Apply this diff to defer expr retrieval until it's actually needed:

 	if (!drizzleDialectSet.has(databaseEngine)) return '';
 
-	const expr = engineGroup[hostKey]?.expr ?? remoteDrizzleInit[hostKey];
-	if (!expr) return '';
-
 	if (databaseEngine === 'mysql' || databaseEngine === 'mariadb') {
 		const mode =
 			databaseHost === 'planetscale' && databaseEngine === 'mysql'
 				? 'planetscale'
 				: 'default';
 
 		return `
 const pool = createPool(getEnv("DATABASE_URL"))
 const db = drizzle(pool, { schema, mode: '${mode}' })
 `;
 	}
 
+	const expr = engineGroup[hostKey]?.expr ?? remoteDrizzleInit[hostKey];
+	if (!expr) return '';
+
 	return `
 const pool = ${expr}
 const db = drizzle(pool, { schema })
 `;

Also applies to: 80-90

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 616ccda and 43f91f5.

📒 Files selected for processing (2)
  • src/generators/db/dockerInitTemplates.ts (1 hunks)
  • src/generators/project/generateDBBlock.ts (4 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-22T04:55:44.021Z
Learnt from: bnziv
Repo: absolutejs/create-absolutejs PR: 11
File: src/generators/configurations/generateEnv.ts:17-17
Timestamp: 2025-11-22T04:55:44.021Z
Learning: The mssql npm package supports Windows-style connection string format (key=value pairs separated by semicolons) in addition to URI format. Connection strings like "Server=localhost,1433;Database=master;User Id=sa;Password=SApassword1;Encrypt=true;TrustServerCertificate=true" are valid for the mssql package.

Applied to files:

  • src/generators/db/dockerInitTemplates.ts
🔇 Additional comments (3)
src/generators/db/dockerInitTemplates.ts (1)

127-127: LGTM! Quote style improvement for readability.

The change from escaped single quotes to double quotes improves readability while maintaining identical functionality in the shell command context.

src/generators/project/generateDBBlock.ts (2)

14-14: Good fix! connectionMap now aligns with non-Drizzle usage.

Updating these entries to new SQL(getEnv("DATABASE_URL")) resolves the inconsistency flagged in the previous review where connectionMap entries were effectively dead code due to the hardcoded branch.

Based on past review comment.

Also applies to: 23-23


72-72: Good simplification! Hardcoded branch removed as suggested.

The removal of the hardcoded special case for mysql/mariadb databaseHost === 'none' makes the code flow through connectionMap consistently for all non-Drizzle cases, addressing the previous review feedback.

Based on past review comment.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/generators/project/generateDBBlock.ts (1)

16-18: MongoDB connection expression appears malformed

connectionMap.mongodb.none currently uses:

none: { expr: 'new MongoClient(getEnv("DATABASE_URL") })' }

The extra }/) will produce invalid generated code. This should be corrected to a balanced call, e.g.:

-		none: { expr: 'new MongoClient(getEnv("DATABASE_URL") })' }
+		none: { expr: 'new MongoClient(getEnv("DATABASE_URL"))' }
🧹 Nitpick comments (3)
src/generators/db/handlerTemplates.ts (1)

327-334: MariaDB drizzle config mirrors MySQL drizzle; consider deduping shared config

The new 'mariadb:drizzle:local' entry correctly reuses the MySql2Database + mysqlDrizzleQueryOperations setup and looks functionally sound. To reduce duplication, you could factor the shared importLines/dbType/queries into a small helper used by both the MySQL and MariaDB drizzle keys.

src/generators/project/generateDBBlock.ts (1)

69-72: Drizzle MySQL/MariaDB branch now hardcodes mysql2 pool; confirm remote Planetscale intent

For orm === 'drizzle' and databaseEngine in { mysql, mariadb }, the block always does:

const pool = createPool(getEnv("DATABASE_URL"))
const db = drizzle(pool, { schema, mode: /* 'default' | 'planetscale' */ })

ignoring the expr from connectionMap/remoteDrizzleInit. This means:

  • Remote MySQL+Planetscale drizzle no longer uses the Planetscale-specific client expression from connectionMap.
  • The runtime now always depends on the mysql2-based path for drizzle MySQL/MariaDB.

Please double-check this is intentional and aligned with the imports/dependency setup (in particular with how generateImportsBlock.ts and createPackageJson.ts handle Planetscale and mysql2). Based on library_context, this is a behavior change from the previous engine-driven approach.

Also applies to: 80-89

src/generators/project/generateImportsBlock.ts (1)

185-199: Centralized drizzle import maps look good; minor redundancy for remote MySQL

The new ormImports / ormDatabaseImports + isDrizzleDialect usage makes the drizzle import path much easier to follow. One side effect is that for drizzle + remote MySQL (e.g. Planetscale), you may now import both the mysql2 drizzle adapter and the remote connector/dialect pair even though generateDBBlock uses only the mysql2 path. This is harmless but slightly noisy; if you want to tighten things up, you could either drop the unused remote imports for that combo or switch generateDBBlock back to using the remote connector expression.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 43f91f5 and 299593f.

📒 Files selected for processing (7)
  • src/generators/configurations/generatePackageJson.ts (3 hunks)
  • src/generators/db/dockerInitTemplates.ts (1 hunks)
  • src/generators/db/generateDockerContainer.ts (3 hunks)
  • src/generators/db/generateDrizzleSchema.ts (3 hunks)
  • src/generators/db/handlerTemplates.ts (1 hunks)
  • src/generators/project/generateDBBlock.ts (4 hunks)
  • src/generators/project/generateImportsBlock.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/generators/db/dockerInitTemplates.ts
  • src/generators/db/generateDockerContainer.ts
🧰 Additional context used
🧬 Code graph analysis (2)
src/generators/project/generateImportsBlock.ts (1)
src/typeGuards.ts (1)
  • isDrizzleDialect (27-30)
src/generators/configurations/generatePackageJson.ts (1)
src/generators/db/dockerInitTemplates.ts (1)
  • initTemplates (112-141)
🔇 Additional comments (2)
src/generators/db/generateDrizzleSchema.ts (1)

16-23: MariaDB dialect wiring is consistent with MySQL/SingleStore

Adding DIALECTS.mariadb and including 'mariadb' in the intBuilder and uidColumn branches makes MariaDB behave like MySQL/SingleStore (int builder + autoincrement PK), which matches the rest of the schema code. This looks correct and consistent.

Also applies to: 73-76, 111-115

src/generators/project/generateImportsBlock.ts (1)

143-183: SingleStore non‑ORM path lacks imports, but proposed package name appears incorrect

The core issue is valid: noOrmImports.singlestore is an empty array, but generateDBBlock.ts line 33 generates code calling createClient({ url: getEnv("DATABASE_URL") }) for the non-ORM SingleStore path. This will cause a runtime error when those symbols are undefined.

However, the proposed fix references @singlestore/db-client, which does not exist as a real npm package. Web search confirms the official SingleStore Node.js packages use names like @singlestore/client. Additionally, handlerTemplates.ts line 391 also references the same non-existent package, suggesting a broader codebase inconsistency.

Before applying the suggested fix, verify:

  • The correct SingleStore package name and export (e.g., is it SingleStoreClient from @singlestore/client, or does the codebase use mysql2 for SingleStore compatibility?)
  • Whether handlerTemplates.ts line 391 has the same issue and should be updated together
  • What the actual generated code should import for SingleStore non-ORM connections

Comment thread src/generators/configurations/generatePackageJson.ts
(!databaseHost || databaseHost === 'none')
) {
const { wait } = initTemplates.mssql;
if (isLocal && databaseEngine === 'mssql') {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this does not us drizzle doesnt that mean we can use the bun version of mssql

volumePath: '/var/opt/mssql'
},
mysql: {
command: '',
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the command is not necessary for most of them make it an optional property instead of giving it empty string

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/generators/db/generateDockerContainer.ts (2)

3-14: Nice centralization of DB templates with a strongly typed map

Defining DatabaseTemplate and using Record<Exclude<DatabaseEngine, 'none' | 'sqlite' | undefined>, DatabaseTemplate> makes the per-engine config much clearer and helps ensure all real engines have entries. The shared volumePath and optional command fields also remove a lot of duplication. No issues here.

If you ever want even stronger guarantees, you could later replace Record<...> with a discriminated union of exact engine keys to get exhaustiveness when adding engines, but what you have is already solid for readability.

Also applies to: 16-16, 22-22, 32-32, 43-43, 53-53, 62-62, 73-73, 83-83, 91-91, 93-93


95-105: Runtime guard could be encoded in the type for stricter callers (optional)

Given this function throws for undefined | 'none' | 'sqlite', its effective domain is already Exclude<DatabaseEngine, 'none' | 'sqlite' | undefined>. To push that invariant to callers and reduce the need for the runtime check, you could expose a narrower parameter type or a small helper that returns a validated engine and use that inside.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cdf5b75 and e46ba0b.

📒 Files selected for processing (1)
  • src/generators/db/generateDockerContainer.ts (9 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/generators/db/generateDockerContainer.ts (1)
src/types.ts (1)
  • DatabaseEngine (45-47)

Comment thread src/generators/db/generateDockerContainer.ts Outdated
@absolutejs absolutejs merged commit 9429e67 into main Nov 24, 2025
1 check was pending
@absolutejs absolutejs deleted the fix/code-cleanup branch November 24, 2025 06:57
This was referenced Nov 24, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants