You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/cli/cli-database.mdx
+82-22Lines changed: 82 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,11 +5,11 @@ description: |
5
5
Choose your ORM and database engine through the interactive wizard, then start writing queries immediately.
6
6
order: 5
7
7
category: CLI
8
-
---
8
+
---
9
9
10
10
## What it does
11
11
12
-
`spraxium database`(alias `spraxium db`) generates a fully wired database module inside your project. It walks you through an interactive wizard where you select an ORM and a database engine, then scaffolds the module files, patches your environment config with the required keys, installs the necessary packages, and optionally registers the module in your *AppModule*. By the end of the wizard your project is ready to run queries with no manual configuration.
12
+
`spraxium database` (alias `spraxium db`) generates a fully wired database module inside your project. It walks you through an interactive wizard where you select an ORM and a database engine, then scaffolds the module files, patches your environment config with the required keys, installs the necessary packages, and optionally registers the module in your _AppModule_. By the end of the wizard your project is ready to run queries with no manual configuration.
13
13
14
14
The command accepts an optional ORM argument to skip the first selection step. When you already know what you want, `spraxium database prisma` jumps directly to the database engine prompt.
15
15
@@ -21,45 +21,89 @@ Use this command at the beginning of a project or when adding database access to
21
21
22
22
<DropdownGroup>
23
23
<Dropdowntitle="Prisma, schema-first with auto-generated client">
24
-
Prisma is the best choice when you want a strongly typed query client generated from a declarative schema file. It supports PostgreSQL, MySQL, and SQLite out of the box. After the wizard runs, define your models in `prisma/schema.prisma` and run `npx prisma migrate dev` to apply changes. Prisma is ideal for teams that prefer schema-as-source-of-truth workflows, readable migration history, and full TypeScript type safety from database to application layer.
24
+
Prisma is the best choice when you want a strongly typed query client
25
+
generated from a declarative schema file. It supports PostgreSQL, MySQL, and
26
+
SQLite out of the box. After the wizard runs, define your models in
27
+
`prisma/schema.prisma` and run `npx prisma migrate dev` to apply changes.
28
+
Prisma is ideal for teams that prefer schema-as-source-of-truth workflows,
29
+
readable migration history, and full TypeScript type safety from database to
Drizzle is suited for projects that value small bundle size, direct SQL control, and schema defined in TypeScript rather than a separate file. It supports PostgreSQL, MySQL, and SQLite. The generated *DatabaseService* exposes a `.getDb()` method that returns the Drizzle query builder, ready to use. Choose Drizzle when you want minimal abstraction with full TypeScript inference and prefer defining tables as TypeScript objects over `.prisma` syntax.
33
+
Drizzle is suited for projects that value small bundle size, direct SQL
34
+
control, and schema defined in TypeScript rather than a separate file. It
35
+
supports PostgreSQL, MySQL, and SQLite. The generated *DatabaseService*
36
+
exposes a `.getDb()` method that returns the Drizzle query builder, ready to
37
+
use. Choose Drizzle when you want minimal abstraction with full TypeScript
38
+
inference and prefer defining tables as TypeScript objects over `.prisma`
39
+
syntax.
28
40
</Dropdown>
29
41
<Dropdowntitle="TypeORM, decorator-based with Active Record or Data Mapper">
30
-
TypeORM is the established choice for teams coming from NestJS or Spring backgrounds who are comfortable with class decorators such as *@Entity*, *@Column*, and *@Repository*. It supports PostgreSQL, MySQL, and SQLite. Use TypeORM when your team prefers entity classes as the source of truth and wants a familiar pattern for migrations and relation management.
42
+
TypeORM is the established choice for teams coming from NestJS or Spring
43
+
backgrounds who are comfortable with class decorators such as *@Entity*,
44
+
*@Column*, and *@Repository*. It supports PostgreSQL, MySQL, and SQLite. Use
45
+
TypeORM when your team prefers entity classes as the source of truth and
46
+
wants a familiar pattern for migrations and relation management.
31
47
</Dropdown>
32
48
<Dropdowntitle="Mongoose, document model for MongoDB">
33
-
Mongoose is the right pick when your data is document-oriented and MongoDB is your database. It has a single database target, so the wizard skips the engine selection step. The generated module includes a schema definition and a service that wraps the Mongoose model. Choose Mongoose for applications that need flexible schemas, embedded documents, or MongoDB-specific query operators.
49
+
Mongoose is the right pick when your data is document-oriented and MongoDB
50
+
is your database. It has a single database target, so the wizard skips the
51
+
engine selection step. The generated module includes a schema definition and
52
+
a service that wraps the Mongoose model. Choose Mongoose for applications
53
+
that need flexible schemas, embedded documents, or MongoDB-specific query
54
+
operators.
34
55
</Dropdown>
35
56
<Dropdowntitle="Mikro-ORM, versatile ORM with Unit of Work pattern">
36
-
Mikro-ORM is a strong choice for advanced use cases that benefit from the Unit of Work pattern and Identity Map. It supports PostgreSQL, MySQL, SQLite, and MongoDB. Mikro-ORM is well suited for complex domain models with deep relation graphs, where controlled change tracking across a request lifecycle matters more than simplicity of setup.
57
+
Mikro-ORM is a strong choice for advanced use cases that benefit from the
58
+
Unit of Work pattern and Identity Map. It supports PostgreSQL, MySQL,
59
+
SQLite, and MongoDB. Mikro-ORM is well suited for complex domain models with
60
+
deep relation graphs, where controlled change tracking across a request
61
+
lifecycle matters more than simplicity of setup.
37
62
</Dropdown>
38
63
</DropdownGroup>
39
64
40
65
## What the wizard does
41
66
42
67
<Steps>
43
68
<Steptitle="ORM selection">
44
-
If you did not pass an ORM as a CLI argument, the wizard presents an interactive list of the five supported ORMs with a short description for each. Navigate with the arrow keys and press Enter to confirm.
69
+
If you did not pass an ORM as a CLI argument, the wizard presents an
70
+
interactive list of the five supported ORMs with a short description for
71
+
each. Navigate with the arrow keys and press Enter to confirm.
45
72
</Step>
46
73
<Steptitle="Database engine selection">
47
-
For ORMs that support multiple engines (Prisma, Drizzle, TypeORM, Mikro-ORM), the wizard asks which engine to target. Mongoose skips this step because it only targets MongoDB.
74
+
For ORMs that support multiple engines (Prisma, Drizzle, TypeORM,
75
+
Mikro-ORM), the wizard asks which engine to target. Mongoose skips this step
76
+
because it only targets MongoDB.
48
77
</Step>
49
78
<Steptitle="Module name">
50
-
The wizard prompts for a module name with `database` as the default. The name is converted to kebab-case for the folder and PascalCase for the class names. A name like `user-db` produces a `UserDbModule` and a `src/modules/user-db/` directory.
79
+
The wizard prompts for a module name with `database` as the default. The
80
+
name is converted to kebab-case for the folder and PascalCase for the class
81
+
names. A name like `user-db` produces a `UserDbModule` and a
82
+
`src/modules/user-db/` directory.
51
83
</Step>
52
84
<Steptitle="File scaffolding">
53
-
The CLI downloads the template for your ORM and engine combination and writes the module, service, schema, and config files into `src/modules/{name}/`. A root-level config file (such as `drizzle.config.ts` or `prisma/schema.prisma`) is also added if the ORM requires it.
85
+
The CLI downloads the template for your ORM and engine combination and
86
+
writes the module, service, schema, and config files into `src/modules/
87
+
{name}/`. A root-level config file (such as `drizzle.config.ts` or
88
+
`prisma/schema.prisma`) is also added if the ORM requires it.
54
89
</Step>
55
90
<Steptitle="Environment key injection">
56
-
The required environment variables (`DATABASE_URL`, `DATABASE_PATH`, etc.) are appended to your `app.env.ts` automatically if they are not already present. No manual editing needed.
91
+
The required environment variables (`DATABASE_URL`, `DATABASE_PATH`, etc.)
92
+
are appended to your `app.env.ts` automatically if they are not already
93
+
present. No manual editing needed.
57
94
</Step>
58
95
<Steptitle="Package installation">
59
-
The wizard asks if you want to install packages immediately. Confirming runs the detected package manager to add runtime dependencies (such as the ORM client and database driver) and dev dependencies (CLI tools, type definitions). Post-install commands like `npx prisma generate` are also run automatically.
96
+
The wizard asks if you want to install packages immediately. Confirming runs
97
+
the detected package manager to add runtime dependencies (such as the ORM
98
+
client and database driver) and dev dependencies (CLI tools, type
99
+
definitions). Post-install commands like `npx prisma generate` are also run
100
+
automatically.
60
101
</Step>
61
102
<Steptitle="AppModule registration">
62
-
If an `app.module.ts` is found in your `src/` directory, the wizard offers to add the generated module to the *imports* array automatically. This connects the module to the DI container so you can inject the *DatabaseService* anywhere in the application.
103
+
If an `app.module.ts` is found in your `src/` directory, the wizard offers
104
+
to add the generated module to the *imports* array automatically. This
105
+
connects the module to the DI container so you can inject the
106
+
*DatabaseService* anywhere in the application.
63
107
</Step>
64
108
</Steps>
65
109
@@ -69,31 +113,47 @@ The exact files vary by ORM but the layout follows the same convention for every
69
113
70
114
<FolderStructure>
71
115
<Foldername="src/modules/database/">
72
-
<File name="database.module.ts" description="Module class with @Module decorator and provider exports" />
73
-
<File name="database.service.ts" description="Injectable service exposing the ORM client or query builder" />
74
-
<File name="database.schema.ts" description="Schema or entity definition (present for Drizzle, Mongoose, Mikro-ORM)" />
116
+
<File
117
+
name="database.module.ts"
118
+
description="Module class with @Module decorator and provider exports"
119
+
/>
120
+
<File
121
+
name="database.service.ts"
122
+
description="Injectable service exposing the ORM client or query builder"
123
+
/>
124
+
<File
125
+
name="database.schema.ts"
126
+
description="Schema or entity definition (present for Drizzle, Mongoose, Mikro-ORM)"
127
+
/>
75
128
</Folder>
76
129
</FolderStructure>
77
130
78
131
<Callouttone="info"title="Root-level config files are also created">
79
-
Some ORMs require a configuration file at the project root. Prisma generates a prisma/ directory with schema.prisma. Drizzle generates drizzle.config.ts. These files are written alongside the module files and should be committed to version control.
132
+
Some ORMs require a configuration file at the project root. Prisma generates a
133
+
prisma/ directory with schema.prisma. Drizzle generates drizzle.config.ts.
134
+
These files are written alongside the module files and should be committed to
135
+
version control.
80
136
</Callout>
81
137
82
138
## After the wizard
83
139
84
-
Once the command finishes, you can inject *DatabaseService* into any handler, guard, or service within the same module scope. The service is exported from the database module, so importing *DatabaseModule* in any other module gives you access to it through the DI container.
140
+
Once the command finishes, you can inject _DatabaseService_ into any handler, guard, or service within the same module scope. The service is exported from the database module, so importing _DatabaseModule_ in any other module gives you access to it through the DI container.
Copy file name to clipboardExpand all lines: en/cli/cli-dev.mdx
+32-14Lines changed: 32 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,11 +9,11 @@ category: CLI
9
9
10
10
## Overview
11
11
12
-
Three commands cover the full development lifecycle in Spraxium: *spraxium dev* for local iteration, *spraxium build* for producing a production artifact, and *spraxium start* for running that artifact. This page covers all three so you never need to jump between pages to understand how they connect.
12
+
Three commands cover the full development lifecycle in Spraxium: _spraxium dev_ for local iteration, _spraxium build_ for producing a production artifact, and _spraxium start_ for running that artifact. This page covers all three so you never need to jump between pages to understand how they connect.
13
13
14
14
## spraxium dev
15
15
16
-
*spraxium dev* starts a file-watching development server that restarts the application automatically when source files change. It uses SWC for loading TypeScript without a separate compile step, keeping restart times short even in large projects. The watcher fires based on the `include` and `exclude` glob patterns in your configuration, and applies a configurable debounce to batch rapid file saves into a single restart.
16
+
_spraxium dev_ starts a file-watching development server that restarts the application automatically when source files change. It uses SWC for loading TypeScript without a separate compile step, keeping restart times short even in large projects. The watcher fires based on the `include` and `exclude` glob patterns in your configuration, and applies a configurable debounce to batch rapid file saves into a single restart.
Glob patterns for files that can trigger a restart. Narrowing this list reduces noisy restarts from files that should not affect runtime behavior.
41
+
Glob patterns for files that can trigger a restart. Narrowing this list
42
+
reduces noisy restarts from files that should not affect runtime behavior.
37
43
</Dropdown>
38
44
39
45
<Dropdowntitle="exclude">
40
-
Files matched here are ignored by the watcher even if they fall inside an `include` pattern. Use this to skip test files, generated code, or any path that changes frequently without affecting the running process.
46
+
Files matched here are ignored by the watcher even if they fall inside an
47
+
`include` pattern. Use this to skip test files, generated code, or any path
48
+
that changes frequently without affecting the running process.
41
49
</Dropdown>
42
50
43
51
<Dropdowntitle="debounce">
@@ -46,7 +54,8 @@ export default {
46
54
</DropdownGroup>
47
55
48
56
<Callouttone="info"title="Default excludes are always on">
49
-
Even with no config block, the watcher ignores node_modules, .git, and .spraxium to prevent restart loops from dependency installs or build output.
57
+
Even with no config block, the watcher ignores node_modules, .git, and
58
+
.spraxium to prevent restart loops from dependency installs or build output.
50
59
</Callout>
51
60
52
61
### Crash recovery
@@ -57,7 +66,7 @@ If the bot process crashes, the dev server does not exit. It applies an exponent
57
66
58
67
## spraxium build
59
68
60
-
*spraxium build* validates types and produces a production-ready bundle. It runs in two sequential steps: first a type-check pass and then the bundler. If the type-check fails, the bundler never runs, so you get a clean exit code that CI pipelines can rely on.
69
+
_spraxium build_ validates types and produces a production-ready bundle. It runs in two sequential steps: first a type-check pass and then the bundler. If the type-check fails, the bundler never runs, so you get a clean exit code that CI pipelines can rely on.
61
70
62
71
```bash filename="terminal"
63
72
spraxium build
@@ -67,24 +76,31 @@ spraxium build
67
76
68
77
<Steps>
69
78
<Steptitle="Type-check">
70
-
Runs `tsc --noEmit` against your project. Any type error fails the command immediately. Fix all TypeScript errors before the bundler can proceed.
79
+
Runs `tsc --noEmit` against your project. Any type error fails the command
80
+
immediately. Fix all TypeScript errors before the bundler can proceed.
71
81
</Step>
72
82
<Steptitle="Bundle">
73
-
Runs `tsdown` with your project's configuration. If a `tsdown.config.*` file exists in the project root, the CLI uses it. Otherwise it applies these defaults: entry points `src/main.ts` and `spraxium.config.ts`, output directory `.spraxium/dist`, format ESM, platform Node, `--clean`, and `--no-dts`.
83
+
Runs `tsdown` with your project's configuration. If a `tsdown.config.*` file
84
+
exists in the project root, the CLI uses it. Otherwise it applies these
85
+
defaults: entry points `src/main.ts` and `spraxium.config.ts`, output
86
+
directory `.spraxium/dist`, format ESM, platform Node, `--clean`, and
87
+
`--no-dts`.
74
88
</Step>
75
89
</Steps>
76
90
77
-
The compiled output lands in `.spraxium/dist/` by default. This directory is the artifact that *spraxium start* looks for.
91
+
The compiled output lands in `.spraxium/dist/` by default. This directory is the artifact that _spraxium start_ looks for.
78
92
79
93
<Callouttone="warning"title="Build does not run tests">
80
-
Running *spraxium build* does not execute your test suite. Run your tests separately before or after, and treat the build as a type and bundle gate only.
94
+
Running *spraxium build* does not execute your test suite. Run your tests
95
+
separately before or after, and treat the build as a type and bundle gate
96
+
only.
81
97
</Callout>
82
98
83
99
---
84
100
85
101
## spraxium start
86
102
87
-
*spraxium start* runs the compiled artifact produced by *spraxium build*. It sets `NODE_ENV=production` before launching and inherits the current process stdio so application logs stream directly to the terminal.
103
+
_spraxium start_ runs the compiled artifact produced by _spraxium build_. It sets `NODE_ENV=production` before launching and inherits the current process stdio so application logs stream directly to the terminal.
88
104
89
105
```bash filename="terminal"
90
106
spraxium start
@@ -102,14 +118,16 @@ The CLI checks the following paths in order and runs the first one it finds:
102
118
6.`build/main.js`
103
119
104
120
<Callouttone="warning"title="No build means no start">
105
-
If none of the candidate paths exist, the command fails and prints a message telling you to run *spraxium build* first. Ensure your environment variables such as DISCORD_TOKEN are loaded before running this command.
121
+
If none of the candidate paths exist, the command fails and prints a message
122
+
telling you to run *spraxium build* first. Ensure your environment variables
123
+
such as DISCORD_TOKEN are loaded before running this command.
106
124
</Callout>
107
125
108
126
---
109
127
110
128
## Typical workflow
111
129
112
-
A complete iteration from development to production follows this order: run *spraxium dev* during active work, then switch to *spraxium build* when preparing a release, and finally run *spraxium start* to verify or deploy the compiled artifact. In CI, skip the dev step entirely and run build then start in sequence as your validation pipeline.
130
+
A complete iteration from development to production follows this order: run _spraxium dev_ during active work, then switch to _spraxium build_ when preparing a release, and finally run _spraxium start_ to verify or deploy the compiled artifact. In CI, skip the dev step entirely and run build then start in sequence as your validation pipeline.
0 commit comments