Add MariaDB support#9
Conversation
WalkthroughAdds 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
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
absolutejs
left a comment
There was a problem hiding this comment.
maria db is supported by drizzle through the mysql adapters
add drizzle support then its good
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (5)
src/generators/db/generateDrizzleSchema.ts (1)
47-55: MariaDB dialect reuses MySQL Drizzle core configurationThe new
mariadbentry mirroring themysqlconfiguration (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 duplicatedrizzleimportsUsing
SQLfrombunfor the non‑ORM MySQL/MariaDB path anddrizzle-orm/mysql2+mysql2/promisefor the ORM path matches the DB block changes and looks coherent.Two follow‑ups to consider:
- For configs where
orm === 'drizzle'anddatabaseHostis remote (e.g. Planetscale), you now importdrizzlefrom both a remote dialect (drizzle-orm/planetscale-serverlessvia the earlierorm === 'drizzle' && isRemoteHost'block) and fromdrizzle-orm/mysql2here. That would lead to conflictingdrizzlenamed 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' && isRemoteHostblock 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+databaseHostand adjust the conditions so that only onedrizzleimport is ever generated for a given configuration.src/generators/configurations/generatePackageJson.ts (1)
205-221: MariaDB Docker dev scripts mirror the existing MySQL setup appropriatelyThe new MariaDB dev scripts (
db:up,db:down,db:reset,db:mariadbplus pre/post hooks) are consistent with the MySQL and PostgreSQL patterns and usemariadb-admin/mariadbappropriately while scoping the compose project tomariadb.The reuse of
MYSQL_PWDis 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 withmodelooks consistent, but check Planetscale integrationUsing 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 amodeoption 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 amodeoption, 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:localandmariadb:drizzle:localare 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/mysqlDrizzleConfigreused 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
📒 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 consistentAdding
'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 goodExtending both
intBuilderand theuidColumnautoincrement 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 usageAdding
mysql2whenever(databaseEngine === 'mysql' || databaseEngine === 'mariadb') && orm === 'drizzle'aligns with the newdrizzle-orm/mysql2imports 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 MySQLAdding a
mariadbentry withcreatePool(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 SQLFor 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
connectionMapfor 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 robustThe new
mysqlSqlQueryOperationsimplementation correctly uses parameterized Bun SQL templates, retrieves the inserted row vialastInsertRowid, and handles missing-row cases with explicit errors. The read helpers mirror other drivers and returnrow ?? nullconsistently. No changes needed here.
351-357: Double-checkpostgresql:drizzle:localdb type vs. Bun SQL importHere
dbTypeisNodePgDatabase<SchemaType>, but the imports bring inBunSQLDatabasefromdrizzle-orm/bun-sqland never importNodePgDatabase. 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
dbTypeto the Bun SQL database type that actually matchesdrizzle-orm/bun-sql.
Summary by CodeRabbit
New Features
Improvements