default db sqlite

This commit is contained in:
Joe Arndt 2026-02-09 23:11:53 -06:00
parent 2ca91b97fb
commit 104b9067c1
4 changed files with 1405 additions and 34 deletions

View file

@ -10,28 +10,44 @@ npm install
```
## Run Locally
By default, the API looks for a locally running Postgres instance, which can be satisfied by running the following `docker` container:
Start the API on [localhost:3000](http://localhost:3000)
```bash
npm run start:dev
```
Default port (`3000`) can be changed by setting the `PORT=xxxx` environment variable.
### Database
There are two databases that are supported:
- Postgres (recommended)
- SQLite (default for simplicity)
For simplicity SQLite is used as the database in the `default`/`unconfigured` state.
Using Postgres is pretty simple, by default the API is looking for a locally running instance, which can be satisfied by running the following `docker` container:
```bash
docker run --name common-cents-db -e POSTGRES_USER=common-cents -e POSTGRES_PASSWORD=CommonCents_123! -p 5432:5432 -d postgres
```
Alternatively, an external Postgres can be configured through an environment file placed in the root directory (`common-cents-api/.env`):
To specify Postgres as the database, set the `DB_TYPE=postgres` environment variable.
Alternatively, an external Postgres can be configured through additional environment variables. To simplify all of this, use an `env`file placed in the root directory (`common-cents-api/.env`):
```text
# .env
DB_SYNC=true # should be false for production environment
DB_HOST=localhost
DB_PORT=5432
DB_USER=common-cents
DB_PASS=CommonCents_123!
DB_NAME=common-cents
# Type 'sqlite' or 'postgres' (if not set sqlite will be used)
DB_TYPE=sqlite
# Sync should be false for production
DB_SYNC=true
# Postgres overrides
PG_HOST=localhost
PG_PORT=5432
PG_USER=common-cents
PG_PASS=CommonCents_123!
```
Once the DB is configured/running, the API can be started:
```bash
npm run start:dev
```
Default port (`3000`) can also be changed in the `.env` file by setting `PORT=xxxx`.
## Bruno
The included `bruno` folder contains a collection of calls to make it more convenient to interact with the API. Local calls assume the default NestJS port (`3000`) is being used.