Skip to content

Add Gel support#20

Merged
absolutejs merged 7 commits intomainfrom
feat/geldb-support
Dec 1, 2025
Merged

Add Gel support#20
absolutejs merged 7 commits intomainfrom
feat/geldb-support

Conversation

@bnziv
Copy link
Copy Markdown
Collaborator

@bnziv bnziv commented Nov 25, 2025

Summary by CodeRabbit

  • New Features

    • Added first-class support for Gel and SingleStore engines (local dev scripts, dependency injection, and client initialization).
    • Drizzle ORM integration extended to Gel and SingleStore with engine-driven database type selection.
    • Docker templates updated for Gel and SingleStore (images, ports, volumes, readiness checks).
  • Behavioral Changes

    • JSON column handling improved for Gel schemas.
    • Database scripts and local workflows updated to include Gel and SingleStore.

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 25, 2025

Walkthrough

Adds Gel and SingleStore support across the code generator: updates env URLs and package scripts, adjusts Docker/init templates and images, converts Gel SQL schema and query helpers to Gel client/Drizzle patterns, and extends type/schema generation to map Drizzle dialects to specific DB implementations.

Changes

Cohort / File(s) Summary
Configuration & scripts
src/generators/configurations/generateEnv.ts, src/generators/configurations/generatePackageJson.ts
Updated database URLs for Gel and SingleStore; added gel and singlestore db scripts; enable local dependency injection for gel (gel@2.1.1) and singlestore (mysql2@3.14.2); removed gel/singlestore from local-exclusion logic.
Docker init & container templates
src/generators/db/dockerInitTemplates.ts, src/generators/db/generateDockerContainer.ts
Converted SQL CREATE TABLEs to Gel type definitions; switched Gel CLI/wait checks to Gel query style; Gel image -> geldata/gel:latest, port -> 5656:5656, volume path -> /var/lib/gel/data, env changes (GEL_SERVER_SECURITY); SingleStore image and volume path updated.
Drizzle schema & DB type mapping
src/generators/db/generateDrizzleSchema.ts, src/generators/db/generateDatabaseTypes.ts
Added json builder for Gel and changed JSON field emission to json(); extend generateDatabaseTypes to accept databaseEngine and map Drizzle dialects (gel, mysql2, bun-sql, singlestore, bun-sqlite) when no host provided.
Query operations & driver configs
src/generators/db/handlerTemplates.ts
Replaced gelSqlQueryOperations with gelClientQueryOperations using Gel client methods (queryRequiredSingle, querySingle); added gel:drizzle:local driver (GelJsDatabase + Drizzle integration); updated gel:sql:local to client-style ops/imports.
Connection init & imports
src/generators/project/generateDBBlock.ts, src/generators/project/generateImportsBlock.ts
Changed connection init for Gel to createClient(getEnv("DATABASE_URL")) and SingleStore to createPool(getEnv("DATABASE_URL")); added Gel and SingleStore imports for Drizzle/no-ORM paths and tightened equality checks to ===.

Sequence Diagram(s)

sequenceDiagram
  participant Generator as Code Generator
  participant AppInit as Generated App (runtime)
  participant GelClient as Gel.createClient()
  participant DB as Gel DB

  Note over Generator: Generator emits connection code and queries

  Generator->>AppInit: write connectionMap (createClient/getEnv)
  AppInit->>GelClient: createClient(getEnv("DATABASE_URL"))
  GelClient->>DB: open connection (5656)
  AppInit->>GelClient: queryRequiredSingle / querySingle
  GelClient->>DB: execute Gel query (insert/select)
  DB-->>GelClient: result row
  GelClient-->>AppInit: typed record / null
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Areas needing extra attention:
    • src/generators/db/handlerTemplates.ts: correctness of Gel client calls and returned shapes
    • src/generators/db/dockerInitTemplates.ts: Gel type definition syntax and readiness/query CLI correctness
    • src/generators/db/generateDatabaseTypes.ts: engine-to-Drizzle mapping and import lines for each dialect

Possibly related PRs

Suggested reviewers

  • absolutejs

Poem

🐇 I hopped through templates, types, and ports,

Gel client now hums in our generated sorts,
JSON builders dancing in drizzle's light,
New images spin up on five-six-five-six night,
A rabbit's small cheer — the DBs take flight! 🥕

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 Gel support' directly and accurately describes the primary change—adding Gel database support across multiple generator files, configuration templates, and integration points.
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/geldb-support

📜 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 e97f954 and 8ddbf6d.

📒 Files selected for processing (8)
  • src/generators/configurations/generateEnv.ts (1 hunks)
  • src/generators/configurations/generatePackageJson.ts (5 hunks)
  • src/generators/db/dockerInitTemplates.ts (3 hunks)
  • src/generators/db/generateDatabaseTypes.ts (2 hunks)
  • src/generators/db/generateDockerContainer.ts (2 hunks)
  • src/generators/db/handlerTemplates.ts (3 hunks)
  • src/generators/project/generateDBBlock.ts (2 hunks)
  • src/generators/project/generateImportsBlock.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/generators/db/dockerInitTemplates.ts
  • src/generators/db/generateDockerContainer.ts
  • src/generators/configurations/generatePackageJson.ts
🧰 Additional context used
🧬 Code graph analysis (2)
src/generators/project/generateImportsBlock.ts (1)
src/typeGuards.ts (1)
  • isDrizzleDialect (27-30)
src/generators/db/generateDatabaseTypes.ts (2)
src/types.ts (3)
  • DatabaseEngine (45-47)
  • DatabaseHost (49-49)
  • AuthProvider (40-40)
src/typeGuards.ts (1)
  • isDrizzleDialect (27-30)
🔇 Additional comments (15)
src/generators/project/generateDBBlock.ts (2)

32-34: LGTM!

The Singlestore connection now uses createPool(getEnv("DATABASE_URL")) which correctly uses the mysql2/promise pool creation API. This is consistent with the import in generateImportsBlock.ts (line 141).


10-12: Gel client API signature verified—change is correct.

The createClient function from 'gel' accepts string | ConnectOptions | null | undefined as its options parameter. Passing getEnv("DATABASE_URL") (a string) directly aligns perfectly with the API signature. The change from the object-based gelClient({ url: ... }) to the direct string argument createClient(getEnv("DATABASE_URL")) is correct and properly utilizes Gel's current API.

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

20-20: LGTM!

Using mysql:// scheme for Singlestore is correct since Singlestore is MySQL wire-protocol compatible.

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

1-2: LGTM!

The new imports for isDrizzleDialect and type definitions are correctly added to support the engine-based type generation.


34-61: I'll verify the concern about cockroachdb handling in the Drizzle dialect switch statement. Let me search the codebase to determine if this is a real issue.
<function_calls>

#!/bin/bash

Check the context around the switch statement and find availableDrizzleDialects

rg -n "availableDrizzleDialects" --type=ts -B 2 -A 10


</function_calls>

#!/bin/bash

Read the full generateDatabaseTypes.ts file to see the complete switch statement

cat -n src/generators/db/generateDatabaseTypes.ts


</function_calls>

#!/bin/bash

Search for any reference to cockroachdb in the codebase

rg -n "cockroachdb" --type=ts -i


</function_calls>

#!/bin/bash

Check if there's a default case in the switch and search for isDrizzleDialect

rg -n "isDrizzleDialect|default:" src/generators/db/generateDatabaseTypes.ts -B 2 -A 2


</function_calls>

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

119-122: LGTM!

The Gel imports for Drizzle ORM are correctly structured, importing createClient from the gel package and drizzle from drizzle-orm/gel.


139-142: LGTM!

The Singlestore imports correctly use drizzle-orm/singlestore and mysql2/promise for the pool creation, which aligns with Singlestore's MySQL-compatible driver.


157-160: LGTM!

The Gel imports for non-ORM usage are consistent with the ORM path.


188-191: LGTM!

The Singlestore imports for non-ORM usage correctly use createPool from mysql2/promise.


204-204: Good practice: strict equality.

The change from == to === improves type safety and follows best practices.

Also applies to: 211-211

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

196-209: LGTM!

The Singlestore query operations now correctly type the result with RowDataPacket[], which is the proper MySQL2 pattern for typed query results.


330-338: LGTM!

The new gel:drizzle:local driver configuration correctly uses GelJsDatabase<SchemaType> and includes proper imports for Drizzle ORM integration with Gel.


339-343: LGTM!

The gel:sql:local configuration correctly updated to use Client type from the gel package with the new gelClientQueryOperations.


406-418: LGTM!

The Singlestore driver configurations are correctly set up:

  • singlestore:sql:local uses Pool with RowDataPacket import for typed queries
  • singlestore:drizzle:local uses SingleStoreDriverDatabase with the MySQL-compatible Drizzle operations

173-194: Verify count field type definition confirmed—the <int16> cast is correct.

The Gel schema definition in src/generators/db/dockerInitTemplates.ts (line 101) explicitly declares the count field in count_history as int16:

create required property count: int16;

The <int16> cast in line 175 of handlerTemplates.ts matches this schema definition and is therefore correct. No type mismatch or overflow risk exists for the Gel client queries.


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: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5cc79b1 and 50cc90f.

📒 Files selected for processing (10)
  • src/generators/configurations/generateEnv.ts (1 hunks)
  • src/generators/configurations/generatePackageJson.ts (3 hunks)
  • src/generators/db/dockerInitTemplates.ts (2 hunks)
  • src/generators/db/generateDatabaseTypes.ts (2 hunks)
  • src/generators/db/generateDockerContainer.ts (1 hunks)
  • src/generators/db/generateDrizzleSchema.ts (1 hunks)
  • src/generators/db/handlerTemplates.ts (2 hunks)
  • src/generators/db/scaffoldDatabase.ts (1 hunks)
  • src/generators/project/generateDBBlock.ts (1 hunks)
  • src/generators/project/generateImportsBlock.ts (3 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/configurations/generateEnv.ts
🧬 Code graph analysis (3)
src/generators/db/generateDatabaseTypes.ts (2)
src/types.ts (3)
  • DatabaseEngine (45-47)
  • DatabaseHost (49-49)
  • AuthProvider (40-40)
src/typeGuards.ts (1)
  • isDrizzleDialect (27-30)
src/generators/configurations/generatePackageJson.ts (1)
src/generators/db/dockerInitTemplates.ts (1)
  • initTemplates (127-156)
src/generators/project/generateImportsBlock.ts (1)
src/typeGuards.ts (1)
  • isDrizzleDialect (27-30)
🔇 Additional comments (15)
src/generators/db/generateDrizzleSchema.ts (1)

4-11: LGTM! Gel dialect now properly supports native JSON.

The addition of json to the builders array and switching from text() to json() for the JSON type aligns the Gel dialect with other databases that have native JSON support. This is consistent with how MySQL, PostgreSQL, and SingleStore handle JSON fields.

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

14-14: LGTM! Gel connection URL updated consistently with Docker configuration.

The new URL format (gel://admin@localhost:5656/main?tls_security=insecure) correctly aligns with:

  • Docker port mapping (5656:5656 in generateDockerContainer.ts)
  • CLI parameters (-u admin, -P 5656, --tls-security insecure in dockerInitTemplates.ts)
  • Insecure dev mode environment variable
src/generators/configurations/generatePackageJson.ts (2)

38-42: LGTM! Gel database scripts configuration added correctly.

The clientCmd correctly uses gel (interactive mode) rather than gel query (for executing queries), which is appropriate for the db:gel script that opens an interactive client session.


250-252: No issues found.

The gel package version 2.1.1 is a valid published version on npm.

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

10-12: LGTM! Gel client initialization updated to use createClient.

The change from gelClient({ url: ... }) to createClient(getEnv("DATABASE_URL")) aligns with the import statement in generateImportsBlock.ts which imports createClient from the gel package.

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

101-106: LGTM! databaseEngine correctly propagated to type generation.

Passing databaseEngine enables generateDatabaseTypes to select the appropriate Drizzle database type (e.g., GelJsDatabase, BunSQLDatabase) when no remote host is specified.

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

119-122: LGTM! Gel-specific Drizzle imports added correctly.

The imports align with the Gel driver setup:

  • createClient from gel for client instantiation
  • drizzle from drizzle-orm/gel for the Drizzle wrapper

108-112: LGTM! User type import added for absoluteAuth.

Adding the User type import when absoluteAuth is enabled provides proper typing for user handlers. This is exported from generateDatabaseTypes.ts at lines 65-66.


154-157: LGTM! Gel imports for non-ORM case added.

Consistent with the Drizzle case, providing createClient from gel and getEnv for database URL retrieval.

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

1-8: LGTM! Type generation now supports engine-based fallback.

The updated signature accepting databaseEngine enables proper DatabaseType selection for local development scenarios where no remote host is configured.


30-57: Ignore this review comment.

The original comment assumes cockroachdb would pass the isDrizzleDialect guard and reach the switch statement, but cockroachdb is not in availableDrizzleDialects. The available Drizzle dialects are: gel, mysql, postgresql, sqlite, and singlestore. Since isDrizzleDialect checks membership against this list, cockroachdb will never enter the conditional block (lines 30–57), so no case is missing.

Likely an incorrect or invalid review comment.

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

24-31: LGTM! Gel Docker image configuration verified and correct.

The geldata/gel:latest tag exists on Docker Hub, confirming the configuration is valid. All settings align with Gel requirements:

  • GEL_SERVER_SECURITY: insecure_dev_mode for local development
  • Port 5656 matches connection URL and CLI commands
  • Volume path /var/lib/gel/data is the standard Gel data directory
src/generators/db/dockerInitTemplates.ts (1)

132-135: LGTM!

The updated CLI and wait commands correctly use the gel query syntax with appropriate connection parameters (-H localhost -P 5656 -u admin --tls-security insecure). The trailing space on line 133 is appropriate for command concatenation.

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

330-338: LGTM

The gel:drizzle:local driver configuration is correct and properly implements Drizzle ORM's Gel support. The configuration follows the established pattern used by other Drizzle drivers (e.g., postgresql:drizzle:local), uses valid imports from the drizzle-orm/gel entrypoint, and references drizzleQueryOperations which contains all required database operations.


339-343: The Client export and import statement are correct.

Verification confirms the gel package exports Client with the required methods. The gelClientQueryOperations configuration uses only valid Client methods (queryRequiredSingle() and querySingle()) that are confirmed in the gel package API. The import change from GelClient to Client is correct and properly aligned with the current package export.

Comment thread src/generators/db/dockerInitTemplates.ts
Comment thread src/generators/db/handlerTemplates.ts
@bnziv bnziv force-pushed the feat/geldb-support branch from 50cc90f to 59e3dfc Compare November 25, 2025 07:04
@bnziv bnziv force-pushed the feat/geldb-support branch from 59e3dfc to 759806b Compare November 25, 2025 07:07
const databaseURLS = {
cockroachdb: 'postgresql://root@localhost:26257/database',
gel: 'gel://user:password@localhost:5432/database',
gel: 'gel://admin@localhost:5656/main?tls_security=insecure',
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.

is using insecure a problem further down the line, like i think that means it needs to run on https correct? if its one of those things where its different for dev and prod we will need to put some sort of toggle

databaseEngine !== 'mongodb' &&
databaseEngine !== 'singlestore' && // TODO: Add support for singlestore
databaseEngine !== 'gel' // TODO: Add support for gel
databaseEngine !== 'singlestore' // TODO: Add support for singlestore
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.

remove the code comment since you added it

gel: {
cli: 'psql -U user -d database -c',
wait: 'until pg_isready -U user -h localhost --quiet; do sleep 1; done'
cli: 'gel query -H localhost -P 5656 -u admin --tls-security insecure -b main ',
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.

same question as above about tls insecure

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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 759806b and e97f954.

📒 Files selected for processing (8)
  • src/generators/configurations/generateEnv.ts (1 hunks)
  • src/generators/configurations/generatePackageJson.ts (3 hunks)
  • src/generators/db/dockerInitTemplates.ts (2 hunks)
  • src/generators/db/generateDatabaseTypes.ts (1 hunks)
  • src/generators/db/generateDockerContainer.ts (1 hunks)
  • src/generators/db/handlerTemplates.ts (2 hunks)
  • src/generators/project/generateDBBlock.ts (1 hunks)
  • src/generators/project/generateImportsBlock.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/generators/configurations/generateEnv.ts
  • src/generators/db/generateDockerContainer.ts
  • src/generators/project/generateDBBlock.ts
  • src/generators/project/generateImportsBlock.ts
  • src/generators/db/generateDatabaseTypes.ts
🧰 Additional context used
🧬 Code graph analysis (1)
src/generators/configurations/generatePackageJson.ts (1)
src/generators/db/dockerInitTemplates.ts (1)
  • initTemplates (128-157)
🔇 Additional comments (7)
src/generators/configurations/generatePackageJson.ts (3)

33-42: Gel dbScripts entry is consistent with existing patterns

The gel entry mirrors how other engines are wired (interactive client command + reuse of initTemplates.gel.wait), so it should integrate cleanly with the db:* scripts.

If you haven’t already, please run the generated db:gel script once to confirm the CLI flags match the Gel CLI you’re targeting.


211-235: Including Gel in local docker-managed DB setup looks correct

Relaxing the condition so that only sqlite and mongodb are excluded means Gel will now get db:up/db:down scripts like the other SQL-ish engines. This aligns with the presence of dbScripts.gel.

Please double-check that the generated db/docker-compose.db.yml contains a db service for Gel so these scripts actually work for that engine.


257-259: Adding the gel runtime dependency for local Gel setups

Wiring gel into dependencies (not devDependencies) when isLocal && databaseEngine === 'gel' matches how the handler templates import Client from 'gel'.

Confirm that the package name (gel) and version (2.1.1) match the published NPM package and the API shape you’re using (e.g., Client, GelJsDatabase).

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

80-92: Gel users type definition looks good

The Gel users type matches the other backends’ shape, and the JSON default via to_json('{}') avoids the <json>{} empty-set pitfall.


133-135: Gel init CLI/wait wiring is aligned with other engines

Using gel query ... for both cli and readiness check mirrors how psql/cockroach sql are used elsewhere and should work for running the generated schema and health probe.

Once the semicolon fix is in, it’s worth running the generated init script (db:init for Gel) to confirm the select 1 wait loop and schema application succeed end-to-end.

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

173-194: Gel client query operations are consistent with the Gel schema

The four operations (insert/select for users and count_history) line up with the Gel types: count as <int16>, uid filtered as <int64>$uid for the sequence-backed key, and JSON metadata inserted via <json>$metadata. Using queryRequiredSingle for inserts and querySingle for selects matches the intended “must-return vs optional” semantics.

Please confirm against the Gel JS client docs that Client.queryRequiredSingle / Client.querySingle accept JS objects for <json> parameters as used here (metadata: userIdentity) without needing manual JSON.stringify.


330-343: New Gel driver configurations hook into the right query sets

The new 'gel:drizzle:local' entry and the updated 'gel:sql:local' entry correctly:

  • Use GelJsDatabase<SchemaType> with drizzle-orm/gel and drizzleQueryOperations for the Drizzle path.
  • Use Client from 'gel' with gelClientQueryOperations for the client path.

This keeps the Gel flows aligned with how other engines are configured.

Double-check that GelJsDatabase is the correct exported type from drizzle-orm/gel and that Client from 'gel' matches the version you’re pinning in package.json, so the generated imports compile.

Comment thread src/generators/db/dockerInitTemplates.ts
@bnziv bnziv force-pushed the feat/geldb-support branch from e97f954 to 8ddbf6d Compare November 26, 2025 07:47
@absolutejs absolutejs merged commit b936a76 into main Dec 1, 2025
1 check passed
@absolutejs absolutejs deleted the feat/geldb-support branch December 1, 2025 07:12
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