-
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.
[ag|#1] add basic sequelize setup (remove typeorm)
- Loading branch information
1 parent
78a32d9
commit 8f878c0
Showing
16 changed files
with
628 additions
and
417 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"development": { | ||
"database": "jsblog_express_sequelize_dev", | ||
"host": "127.0.0.1", | ||
"dialect": "postgres" | ||
}, | ||
"test": { | ||
"database": "jsblog_express_sequelize_test", | ||
"host": "127.0.0.1", | ||
"dialect": "postgres", | ||
"logging": false | ||
} | ||
} |
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,16 @@ | ||
import * as db from "db.json" | ||
|
||
const defaults = { | ||
port: 8081, | ||
hostname: "localhost", | ||
} | ||
|
||
const test = { | ||
...defaults, | ||
db: db.test, | ||
} | ||
|
||
const development = { | ||
...defaults, | ||
db: db.development, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"use strict" | ||
|
||
import * as Sequelize from "sequelize" | ||
import {values, forEach} from "lodash" | ||
|
||
const env = process.env.NODE_ENV || "development" | ||
const config = require(__dirname + "/../config/")[env] | ||
|
||
export const initDb = () => { | ||
|
||
const sequelize = config.use_env_variable | ||
? new Sequelize(process.env[config.use_env_variable], config) | ||
: new Sequelize(config.database, config.username, config.password, config) | ||
|
||
const db = { | ||
// import model factories here, like: | ||
// `Person: personFactory(sequelize, Sequelize)` | ||
} | ||
|
||
forEach(values(db), (mdl: any) => mdl.associate && mdl.associate(db)) | ||
|
||
return {...db, sequelize, Sequelize } | ||
} | ||
|
||
export default initDb() |
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
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
src/migration/1528838191301-AddColumnsToUserAndCreatePhone.ts
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 @@ | ||
import {DataTypeAbstract, DefineAttributeColumnOptions} from "sequelize" | ||
|
||
declare type SequelizeAttributes<T extends{ [key: string]: any}> = { | ||
[P in keyof T]: string | DataTypeAbstract | DefineAttributeColumnOptions | ||
} | ||
|
||
declare interface BaseAttributes { | ||
id?: number, | ||
archived?: string, | ||
createdAt?: string, | ||
updatedAt?: string, | ||
} |
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
Oops, something went wrong.