Skip to content

Commit f384ccd

Browse files
committed
Created sequelize config and cat model
1 parent 6dfb54d commit f384ccd

File tree

6 files changed

+184
-60
lines changed

6 files changed

+184
-60
lines changed

package-lock.json

Lines changed: 128 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
"dependencies": {
2020
"@types/jest": "^24.0.11",
2121
"@types/node": "^11.11.5",
22-
"sequelize-typescript": "^1.0.0-alpha.9",
2322
"jest": "^24.5.0",
23+
"reflect-metadata": "^0.1.13",
24+
"sequelize": "^5.8.7",
25+
"sequelize-typescript": "^1.0.0-alpha.9",
2426
"ts-jest": "^24.0.2",
2527
"ts-node": "^8.0.3"
2628
}

src/app.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require("module-alias/register")
2+
import {Sequelize} from "sequelize-typescript";
3+
4+
export default class App{
5+
public async start() {
6+
const database = this.createSequelizeInstance();
7+
8+
await database.sync();
9+
}
10+
11+
createSequelizeInstance(): Sequelize{
12+
// For below way of setting the config to work, you need to set the target to es6 under compileroptions in tsconfig.json
13+
return new Sequelize({
14+
database: "127.0.0.1",
15+
dialect: "postgres",
16+
username: "notsosecret",
17+
password: "unicorn",
18+
omitNull: true,
19+
modelPaths: [__dirname + "/models"],
20+
modelMatch: (filename, member) => {
21+
return filename.substring(0, filename.indexOf(".model")) == member.toLowerCase();
22+
}
23+
})
24+
}
25+
}
26+
27+
new App().start()

src/models/cat.model.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {Table, Column, Model, Unique, PrimaryKey, AutoIncrement} from 'sequelize-typescript';
2+
3+
@Table
4+
export default class Cat extends Model<Cat> {
5+
@PrimaryKey
6+
@AutoIncrement
7+
@Unique
8+
@Column
9+
id!: number;
10+
11+
@Column
12+
name!: string;
13+
14+
@Column
15+
age!: number;
16+
17+
@Column
18+
isMale!: boolean
19+
}

test/mock-constructor.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
beforeEach(() => {
23
jest.resetAllMocks();
34
});

tsconfig.json

Lines changed: 6 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,10 @@
11
{
22
"compilerOptions": {
3-
/* Basic Options */
4-
// "incremental": true, /* Enable incremental compilation */
5-
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
6-
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
7-
// "lib": [], /* Specify library files to be included in the compilation. */
8-
// "allowJs": true, /* Allow javascript files to be compiled. */
9-
// "checkJs": true, /* Report errors in .js files. */
10-
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
11-
// "declaration": true, /* Generates corresponding '.d.ts' file. */
12-
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
13-
// "sourceMap": true, /* Generates corresponding '.map' file. */
14-
// "outFile": "./", /* Concatenate and emit output to single file. */
15-
// "outDir": "./", /* Redirect output structure to the directory. */
16-
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
17-
// "composite": true, /* Enable project compilation */
18-
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
19-
// "removeComments": true, /* Do not emit comments to output. */
20-
// "noEmit": true, /* Do not emit outputs. */
21-
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
22-
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
23-
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
24-
25-
/* Strict Type-Checking Options */
26-
"strict": true, /* Enable all strict type-checking options. */
27-
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
28-
// "strictNullChecks": true, /* Enable strict null checks. */
29-
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
30-
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
31-
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
32-
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
33-
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
34-
35-
/* Additional Checks */
36-
// "noUnusedLocals": true, /* Report errors on unused locals. */
37-
// "noUnusedParameters": true, /* Report errors on unused parameters. */
38-
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
39-
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
40-
41-
/* Module Resolution Options */
42-
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
43-
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
44-
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
45-
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
46-
// "typeRoots": [], /* List of folders to include type definitions from. */
47-
// "types": [], /* Type declaration files to be included in compilation. */
48-
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
49-
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
50-
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
51-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
52-
53-
/* Source Map Options */
54-
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
55-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
56-
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
57-
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
58-
59-
/* Experimental Options */
60-
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
61-
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
3+
"target": "es6",
4+
"module": "commonjs",
5+
"strict": true,
6+
"esModuleInterop": true,
7+
"experimentalDecorators": true,
8+
"emitDecoratorMetadata": true
629
}
6310
}

0 commit comments

Comments
 (0)