-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
272907f
commit a233630
Showing
31 changed files
with
2,468 additions
and
468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
"dirsfirst", | ||
"eslintignore", | ||
"fullname", | ||
"hstore", | ||
"LGPL", | ||
"nargs", | ||
"nodemon", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
config: './src/database/postgres/config.js', | ||
'migrations-path': './src/database/postgres/migrations/' | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
interface UserDBO { | ||
id: number | ||
name: string | ||
lastName: string | ||
createdAt: Date | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './mongo' | ||
export * from './postgres' |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require('dotenv').config() | ||
|
||
module.exports = { | ||
development: { | ||
url: process.env.DB_URI, | ||
dialect: 'postgres' | ||
}, | ||
production: { | ||
url: process.env.DB_URI, | ||
dialect: 'postgres' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Sequelize } from 'sequelize-typescript' | ||
import { FastifyLoggerInstance } from 'fastify' | ||
|
||
import * as models from './models' | ||
import { join } from 'path' | ||
|
||
let sequelize: Sequelize | ||
|
||
const dbConnection = async ( | ||
logger?: FastifyLoggerInstance | ||
): Promise<{ | ||
connect: () => Promise<Sequelize> | ||
disconnect: () => Promise<void> | ||
createMigration: (migrationName: string) => Promise<void> | ||
}> => { | ||
return { | ||
connect: async () => { | ||
if (!sequelize) { | ||
sequelize = new Sequelize(process.env.DB_URI as string, { | ||
models: Object.values(models) | ||
}) | ||
logger?.info('Postgres connection established.') | ||
} | ||
|
||
return sequelize | ||
}, | ||
disconnect: () => { | ||
logger?.info('Postgres connection closed.') | ||
|
||
return sequelize?.close() | ||
}, | ||
createMigration: async (migrationName: string) => { | ||
const { SequelizeTypescriptMigration } = await import( | ||
'sequelize-typescript-migration-lts' | ||
) | ||
|
||
await SequelizeTypescriptMigration.makeMigration(sequelize, { | ||
outDir: join(__dirname, './migrations'), | ||
migrationName, | ||
preview: false | ||
}) | ||
} | ||
} | ||
} | ||
|
||
export { dbConnection } |
2 changes: 1 addition & 1 deletion
2
example/fastify/src/database/mongo/index.ts → ...le/fastify/src/database/postgres/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './connection' | ||
export * from './models' | ||
export * from './queries' | ||
export * from './connection' |
Oops, something went wrong.