Skip to content

Commit 756ff7f

Browse files
committed
Initial commit
0 parents  commit 756ff7f

10 files changed

+864
-0
lines changed

.gitignore

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
2+
# Created by https://www.gitignore.io/api/node,webstorm
3+
4+
### Node ###
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
24+
# nyc test coverage
25+
.nyc_output
26+
27+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
28+
.grunt
29+
30+
# Bower dependency directory (https://bower.io/)
31+
bower_components
32+
33+
# node-waf configuration
34+
.lock-wscript
35+
36+
# Compiled binary addons (http://nodejs.org/api/addons.html)
37+
build/Release
38+
39+
# Dependency directories
40+
node_modules/
41+
jspm_packages/
42+
43+
# Typescript v1 declaration files
44+
typings/
45+
46+
# Optional npm cache directory
47+
.npm
48+
49+
# Optional eslint cache
50+
.eslintcache
51+
52+
# Optional REPL history
53+
.node_repl_history
54+
55+
# Output of 'npm pack'
56+
*.tgz
57+
58+
# Yarn Integrity file
59+
.yarn-integrity
60+
61+
# dotenv environment variables file
62+
.env
63+
64+
65+
### WebStorm ###
66+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
67+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
68+
69+
# User-specific stuff:
70+
.idea/**/workspace.xml
71+
.idea/**/tasks.xml
72+
.idea/dictionaries
73+
74+
# Sensitive or high-churn files:
75+
.idea/**/dataSources/
76+
.idea/**/dataSources.ids
77+
.idea/**/dataSources.xml
78+
.idea/**/dataSources.local.xml
79+
.idea/**/sqlDataSources.xml
80+
.idea/**/dynamic.xml
81+
.idea/**/uiDesigner.xml
82+
83+
# Gradle:
84+
.idea/**/gradle.xml
85+
.idea/**/libraries
86+
87+
# CMake
88+
cmake-build-debug/
89+
90+
# Mongo Explorer plugin:
91+
.idea/**/mongoSettings.xml
92+
93+
## File-based project format:
94+
*.iws
95+
96+
## Plugin-specific files:
97+
98+
# IntelliJ
99+
/out/
100+
101+
# mpeltonen/sbt-idea plugin
102+
.idea_modules/
103+
104+
# JIRA plugin
105+
atlassian-ide-plugin.xml
106+
107+
# Cursive Clojure plugin
108+
.idea/replstate.xml
109+
110+
# Ruby plugin and RubyMine
111+
/.rakeTasks
112+
113+
# Crashlytics plugin (for Android Studio and IntelliJ)
114+
com_crashlytics_export_strings.xml
115+
crashlytics.properties
116+
crashlytics-build.properties
117+
fabric.properties
118+
119+
### WebStorm Patch ###
120+
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
121+
122+
# *.iml
123+
# modules.xml
124+
# .idea/misc.xml
125+
# *.ipr
126+
127+
# Sonarlint plugin
128+
.idea/sonarlint
129+
130+
131+
# End of https://www.gitignore.io/api/node,webstorm

db/index.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import Sequelize from 'sequelize'
2+
import config from 'config'
3+
import path from 'path'
4+
import sqlite from 'sqlite3'
5+
6+
import Members from '../proxies/Members'
7+
import Meals from '../proxies/Meals'
8+
import MealsMembers from '../proxies/MealsMembers'
9+
10+
const db = config.get('db');
11+
12+
13+
/*
14+
* Store models
15+
*/
16+
let models = { Members: null, Meals: null, MealsMembers: null};
17+
18+
19+
20+
/**
21+
* Resolve path to file
22+
* @param dir
23+
* @returns {string | *}
24+
*/
25+
const resolve = (dir) => path.join(__dirname, '..', dir);
26+
27+
28+
/**
29+
* Create connection to database
30+
*/
31+
const init = async () => {
32+
33+
const sequelize = new Sequelize({
34+
database: db,
35+
username: null,
36+
password: null,
37+
dialect: 'sqlite',
38+
storage: `${db}.db`
39+
});
40+
41+
42+
return sequelize.authenticate()
43+
.then(_ => {
44+
45+
/*
46+
* Include Members' model
47+
* Include Meals' model
48+
*/
49+
const members = sequelize.import(resolve("/models/Members"));
50+
const meals = sequelize.import(resolve("/models/Meals"));
51+
const meals_members = sequelize.import(resolve("/models/MealsMembers"));
52+
53+
54+
/*
55+
* Init proxies
56+
*/
57+
models.Members = new Members(members, {meals, meals_members});
58+
models.Meals = new Meals(meals, {members, meals_members}, sequelize);
59+
models.MealsMembers = new MealsMembers(meals_members, {meals, members});
60+
61+
62+
/*
63+
* Sync models
64+
*/
65+
sequelize.sync();
66+
67+
})
68+
.catch(err => console.error('DB: Unable to connect to the database:', err));
69+
};
70+
71+
72+
export default { init, models };

0 commit comments

Comments
 (0)