Skip to content

Commit

Permalink
Add database configuration
Browse files Browse the repository at this point in the history
along the lines of Sequelize options
  • Loading branch information
mrkvon committed Oct 11, 2023
1 parent 7965615 commit b476488
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ SMTP_TRANSPORT_REQUIRE_TLS=

# email address which will be the sender of the notifications and email verification messages
EMAIL_SENDER=[email protected]

# Database configuration
DB_DIALECT=sqlite
DB_STORAGE=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
DB_HOST=
DB_PORT=
12 changes: 12 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dotenv/config'
import SMTPTransport from 'nodemailer/lib/smtp-transport'
import { Dialect, Options } from 'sequelize'

// the defaults work for tests. you should define your own
// either via .env file, or via environment variables directly (depends on your setup)
Expand Down Expand Up @@ -40,3 +41,14 @@ export const port: number = +(process.env.PORT ?? 3005)

// email verification expiration in milliseconds (1 hour)
export const emailVerificationExpiration = 3600 * 1000

// configuration of database in form of sequelize options
export const database: Options = {
dialect: (process.env.DB_DIALECT as Dialect) ?? 'sqlite',
storage: process.env.DB_STORAGE || undefined, // Path to the SQLite database file (default is memory)
database: process.env.DB_DATABASE || undefined,
username: process.env.DB_USERNAME || undefined,
password: process.env.DB_PASSWORD || undefined,
host: process.env.DB_HOST || undefined,
port: process.env.DB_PORT ? +process.env.DB_PORT : undefined,
}
4 changes: 2 additions & 2 deletions src/config/sequelize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
Model,
Sequelize,
} from 'sequelize'
import { database } from '.'

export const sequelize = new Sequelize({
dialect: 'sqlite',
// storage: 'database.sqlite', // Path to the SQLite database file (default is memory)
logging: false,
...database,
})

export class EmailVerification extends Model<
Expand Down

0 comments on commit b476488

Please sign in to comment.