Skip to content

Add MariaDB support#9

Merged
absolutejs merged 7 commits intomainfrom
feat/mariadb-support
Nov 19, 2025
Merged

Add MariaDB support#9
absolutejs merged 7 commits intomainfrom
feat/mariadb-support

Conversation

@bnziv
Copy link
Copy Markdown
Collaborator

@bnziv bnziv commented Nov 16, 2025

Summary by CodeRabbit

  • New Features

    • Full MariaDB engine support, including local Docker-based initialization and helper scripts for development.
  • Improvements

    • Expanded ORM (Drizzle) and driver compatibility with MariaDB for queries and schema generation.
    • Updated local database connection defaults and initialization behavior for more reliable local development.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 16, 2025

Walkthrough

Adds broad MariaDB support across generators: updates env URLs, package.json scripts/deps, Docker init templates, query handler templates, drizzle schema/dialect entries, and project import/DB block generation to treat MariaDB alongside MySQL with adjusted connection and initialization semantics.

Changes

Cohort / File(s) Summary
Environment URLs
src/generators/configurations/generateEnv.ts
Updated database URL constants: mariadb and mysql connection strings now use user:userpassword credentials.
Package.json generation & scripts
src/generators/configurations/generatePackageJson.ts
Extended mysql→drizzle dependency handling to include MariaDB; added MariaDB-specific docker/dev scripts and db:* script blocks when host is absent.
Docker init templates
src/generators/db/dockerInitTemplates.ts
MariaDB CLI invocations now include explicit database argument; startup wait checks use mariadb-admin ping instead of mysqladmin ping.
Query handler templates & drivers
src/generators/db/handlerTemplates.ts
Simplified/removed handlerTypes usage, adjusted result-capture patterns (removed array-destructuring for rows), removed mariadb-specific query ops block, added mariadb:drizzle driver config and unified SQL import style.
Project DB generation & imports
src/generators/project/generateDBBlock.ts, src/generators/project/generateImportsBlock.ts
Non-Drizzle paths for mysql/mariadb now initialize db = new SQL(getEnv("DATABASE_URL")) (pool → db); Drizzle paths updated to include mariadb with mode logic refined (planetscale only for mysql+planetscale host); imports and getEnv inclusion extended to MariaDB.
Drizzle schema/dialect data
src/generators/db/generateDrizzleSchema.ts, src/data.ts
Added mariadb dialect entry in DIALECTS, aligned integer/uid builder logic with mysql/singlestore; added 'mariadb' to availableDrizzleDialects.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Gen as Generator
  participant Templates as Templates
  participant DBLib as Generated DB Code
  Note over Gen,Templates: New: MariaDB path introduced alongside MySQL

  Gen->>Templates: decide databaseEngine & orm
  alt orm is drizzle
    Templates->>DBLib: emit drizzle init (mysql/mysql2 or mariadb) with mode calc
    DBLib-->>Gen: drizzle + pool setup block
  else orm is none
    Templates->>DBLib: emit non-ORM SQL import (bun SQL) and const db = new SQL(getEnv(...))
    DBLib-->>Gen: non-Drizzle db init block
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Areas needing careful review:
    • src/generators/project/generateDBBlock.ts — changed control flow and DB init semantics (pool → db) and planetscale mode logic.
    • src/generators/db/handlerTemplates.ts — query result handling and driver configurations; ensure return shapes match consumers.
    • src/generators/configurations/generatePackageJson.ts & dockerInitTemplates.ts — script correctness and CLI syntax for MariaDB.
    • src/generators/configurations/generateEnv.ts — verify credential change (userpassword) is intentional.

Poem

🐰
Hops of code in tidy rows,
Maria joins the engine shows,
Pools now db, credentials fine,
Scripts and dialects all align,
A merry rabbit bites the vine — hooray, devs, it's time! 🥕

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 'Add MariaDB support' accurately and concisely summarizes the main objective of this pull request, which adds comprehensive MariaDB database engine support across multiple code generation modules.
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 feat/mariadb-support

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
Owner

@absolutejs absolutejs left a comment

Choose a reason for hiding this comment

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

maria db is supported by drizzle through the mysql adapters

add drizzle support then its good

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 (5)
src/generators/db/generateDrizzleSchema.ts (1)

47-55: MariaDB dialect reuses MySQL Drizzle core configuration

The new mariadb entry mirroring the mysql configuration (same builders, mysqlTable, mysql-core) is a reasonable way to support MariaDB via Drizzle’s MySQL primitives. You might consider extracting a shared “mysql-like” base object to avoid future drift between mysql and mariadb definitions, but that’s purely optional.

Please double‑check against the current Drizzle ORM docs that using the MySQL core/table APIs is still the recommended way to target MariaDB.

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

133-146: MySQL/MariaDB Bun SQL + drizzle/mysql2 wiring is correct but watch for duplicate drizzle imports

Using SQL from bun for the non‑ORM MySQL/MariaDB path and drizzle-orm/mysql2 + mysql2/promise for the ORM path matches the DB block changes and looks coherent.

Two follow‑ups to consider:

  • For configs where orm === 'drizzle' and databaseHost is remote (e.g. Planetscale), you now import drizzle from both a remote dialect (drizzle-orm/planetscale-serverless via the earlier orm === 'drizzle' && isRemoteHost' block) and from drizzle-orm/mysql2 here. That would lead to conflicting drizzle named imports in the generated file. Gating this mysql2 import with !isRemoteHost (or similar) or aliasing one of the imports would avoid that.
  • For the non‑ORM path, DB initialization for MySQL/MariaDB now always goes through Bun SQL, but the databaseEngine === 'mysql' && isRemoteHost block above still adds the Planetscale connector import, which becomes unused in that scenario. It’s harmless but could be cleaned up by conditioning that block on !noOrm.

Please verify the intended combinations of databaseEngine + databaseHost and adjust the conditions so that only one drizzle import is ever generated for a given configuration.

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

205-221: MariaDB Docker dev scripts mirror the existing MySQL setup appropriately

The new MariaDB dev scripts (db:up, db:down, db:reset, db:mariadb plus pre/post hooks) are consistent with the MySQL and PostgreSQL patterns and use mariadb-admin/mariadb appropriately while scoping the compose project to mariadb.

The reuse of MYSQL_PWD is fine for local/dev given MariaDB’s compatibility, but if you ever want stricter clarity you could switch to a MariaDB‑specific env var name in the compose file and script.

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

88-97: Drizzle path for MySQL/MariaDB with mode looks consistent, but check Planetscale integration

Using a dedicated branch for databaseEngine === 'mysql' || databaseEngine === 'mariadb' and computing:

const mode =
  databaseHost === 'planetscale' && databaseEngine === 'mysql'
    ? 'planetscale'
    : 'default';

keeps MariaDB on the default mode and only enables the Planetscale‑specific mode for MySQL. That matches the intent of the new drizzle/mysql2 imports.

However, in configurations where drizzle is imported from a serverless dialect (e.g. drizzle-orm/planetscale-serverless), passing a mode option may not be necessary or even supported. It would be worth double‑checking that the drizzle variant you import for each host+engine combination actually accepts a mode option, and if not, conditionally omit it.

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

315-327: MariaDB configs correctly mirror MySQL paths; consider deduping to avoid drift

mariadb:sql:local and mariadb:drizzle:local are wired to the same query operations and driver types as their MySQL counterparts, which matches the intended “treat MariaDB like MySQL” behavior. This should work fine with Bun SQL and Drizzle given their MySQL/MariaDB compatibility.

If you want to reduce maintenance overhead, you could optionally factor out the shared configs so MySQL and MariaDB literally reference the same objects (e.g., a shared mysqlSqlConfig / mysqlDrizzleConfig reused for both keys), avoiding future divergence.

-const driverConfigurations = {
+const mysqlSqlLocal = {
+  dbType: 'SQL',
+  importLines: `import { SQL } from 'bun'`,
+  queries: mysqlSqlQueryOperations,
+} as const;
+
+const mysqlDrizzleLocal = {
+  dbType: 'MySql2Database<SchemaType>',
+  importLines: `
+import { eq } from 'drizzle-orm'
+import { MySql2Database } from 'drizzle-orm/mysql2'
+import { schema, type SchemaType } from '../../../db/schema'`,
+  queries: mysqlDrizzleQueryOperations,
+} as const;
+
+const driverConfigurations = {
@@
-  'mariadb:sql:local': {
-    dbType: 'SQL',
-    importLines: `import { SQL } from 'bun'`,
-    queries: mysqlSqlQueryOperations
-  },
-  'mariadb:drizzle:local': {
-    dbType: 'MySql2Database<SchemaType>',
-    importLines: `
-import { eq } from 'drizzle-orm'
-import { MySql2Database } from 'drizzle-orm/mysql2'
-import { schema, type SchemaType } from '../../../db/schema'`,
-    queries: mysqlDrizzleQueryOperations
-  },
+  'mariadb:sql:local': mysqlSqlLocal,
+  'mariadb:drizzle:local': mysqlDrizzleLocal,
@@
-  'mysql:drizzle:local': {
-    dbType: 'MySql2Database<SchemaType>',
-    importLines: `
-import { eq } from 'drizzle-orm'
-import { MySql2Database } from 'drizzle-orm/mysql2'
-import { schema, type SchemaType } from '../../../db/schema'`,
-    queries: mysqlDrizzleQueryOperations
-  },
-  'mysql:sql:local': {
-    dbType: 'SQL',
-    importLines: `import { SQL } from 'bun'`,
-    queries: mysqlSqlQueryOperations
-  },
+  'mysql:drizzle:local': mysqlDrizzleLocal,
+  'mysql:sql:local': mysqlSqlLocal,

Also applies to: 347-349

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2623366 and bee4af1.

📒 Files selected for processing (6)
  • src/data.ts (1 hunks)
  • src/generators/configurations/generatePackageJson.ts (2 hunks)
  • src/generators/db/generateDrizzleSchema.ts (3 hunks)
  • src/generators/db/handlerTemplates.ts (3 hunks)
  • src/generators/project/generateDBBlock.ts (2 hunks)
  • src/generators/project/generateImportsBlock.ts (1 hunks)
🔇 Additional comments (7)
src/data.ts (1)

14-21: MariaDB dialect addition to Drizzle list is consistent

Adding 'mariadb' here aligns Drizzle dialects with the existing database engines and Prisma dialects that already include MariaDB; looks consistent with the rest of the PR.

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

72-75: Aligning MariaDB with MySQL integer/uid behavior looks good

Extending both intBuilder and the uidColumn autoincrement branch to include 'mariadb' keeps integer handling and primary key generation consistent across mysql, singlestore, and mariadb. This matches the new DIALECTS entry and should generate coherent schemas for all three engines.

Also applies to: 108-115

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

183-185: mysql2 dependency extension to MariaDB matches drizzle/mysql2 usage

Adding mysql2 whenever (databaseEngine === 'mysql' || databaseEngine === 'mariadb') && orm === 'drizzle' aligns with the new drizzle-orm/mysql2 imports and pool usage in the project generators. This keeps runtime dependencies in sync with the generated code.

Please confirm against the current Drizzle ORM + mysql2 documentation that MariaDB is still supported via the mysql2 driver and doesn’t require any extra configuration flags.

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

13-15: MariaDB entry in connection map aligns with MySQL

Adding a mariadb entry with createPool(getEnv("DATABASE_URL")) for the local (none) host mirrors the MySQL setup and provides the expected pool expression for the drizzle path.


69-80: Non‑ORM MySQL/MariaDB now unified on Bun SQL

For the non‑drizzle branch, routing both MySQL and MariaDB through:

const db = new SQL(getEnv("DATABASE_URL"))

is consistent with the new import logic and simplifies the connection story (local vs host no longer matters for these engines). Just be aware this intentionally ignores any host‑specific expressions in connectionMap for mysql/mariadb; if you ever reintroduce a special remote host handling here, you’ll want to revisit this early return.

Please confirm that the targeted Bun version in your templates supports new SQL(DATABASE_URL) for both MySQL and MariaDB URLs as you expect.

src/generators/db/handlerTemplates.ts (2)

206-266: MySQL/MariaDB Bun SQL operations look consistent and robust

The new mysqlSqlQueryOperations implementation correctly uses parameterized Bun SQL templates, retrieves the inserted row via lastInsertRowid, and handles missing-row cases with explicit errors. The read helpers mirror other drivers and return row ?? null consistently. No changes needed here.


351-357: Double-check postgresql:drizzle:local db type vs. Bun SQL import

Here dbType is NodePgDatabase<SchemaType>, but the imports bring in BunSQLDatabase from drizzle-orm/bun-sql and never import NodePgDatabase. That’s likely to confuse the generated handler types (or fail type-checking) if this configuration is used.

I’d suggest reviewing whether this config should:

  • Import and use NodePgDatabase (node-postgres driver), or
  • Switch dbType to the Bun SQL database type that actually matches drizzle-orm/bun-sql.

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