beech-api 3.5.12 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +400 -185
- package/index.js +2 -3
- package/package.json +9 -6
- package/packages/cli/beech +2 -2
- package/packages/cli/bin/{beech.js → beech-app.js} +86 -28
- package/packages/cli/bin/beech-service.js +40 -212
- package/packages/cli/core/auth/Credentials.js +76 -35
- package/packages/cli/core/auth/Passport.js +318 -188
- package/packages/cli/core/auth/_Request.js +12 -0
- package/packages/cli/core/configure/_gitignore +9 -1
- package/packages/cli/core/configure/app.config-basic.js +10 -10
- package/packages/cli/core/configure/app.config-sequelize.js +12 -12
- package/packages/cli/core/configure/beech.config.js +8 -0
- package/packages/cli/core/configure/global.config-basic.js +4 -4
- package/packages/cli/core/configure/global.config-sequelize.js +4 -4
- package/packages/cli/core/configure/passport.config.js +5 -15
- package/packages/cli/core/databases/mysql.js +53 -29
- package/packages/cli/core/databases/sequelize.js +135 -107
- package/packages/cli/core/databases/test.js +168 -0
- package/packages/cli/core/file-walk/file-walk.js +31 -14
- package/packages/cli/core/generator/_add-on +15 -2
- package/packages/cli/core/generator/_endpoints +15 -82
- package/packages/cli/core/generator/_endpoints_basic +39 -0
- package/packages/cli/core/generator/_help +12 -11
- package/packages/cli/core/generator/_help_create +11 -0
- package/packages/cli/core/generator/{_service → _help_service} +4 -1
- package/packages/cli/core/generator/_models +20 -15
- package/packages/cli/core/generator/{_basic-models → _models_basic} +0 -2
- package/packages/cli/core/generator/_package +4 -3
- package/packages/cli/core/generator/index.js +302 -95
- package/packages/cli/core/helpers/math.js +55 -0
- package/packages/cli/core/helpers/poolEntity.js +31 -0
- package/packages/cli/core/index.js +96 -28
- package/packages/cli/core/origin/index.js +2 -0
- package/packages/cli/core/origin/whitelist/cors.js +91 -0
- package/packages/cli/core/services/http.express.js +338 -203
- package/packages/cli/core/test/utils.js +5 -5
- package/packages/lib/index.js +4 -0
- package/packages/lib/src/endpoint.js +98 -0
- package/packages/lib/src/salt.js +3 -0
- package/packages/lib/src/schema.js +62 -0
- package/packages/lib/src/user.js +196 -0
- package/packages/package.json +4 -7
- package/packages/cli/core/generator/_create +0 -7
- package/packages/lib/beech.js +0 -136
- package/packages/lib/salt.js +0 -3
- package/packages/src-/Add-on.js +0 -9
- package/packages/src-/endpoints/hello-endpoints.js +0 -118
- package/packages/src-/endpoints/test2-endpoints.js +0 -75
- package/packages/src-/endpoints/testSequalize-endpoints.js +0 -23
- package/packages/src-/helpers/Test2.js +0 -11
- package/packages/src-/helpers/my/Test.js +0 -11
- package/packages/src-/helpers/my/Test2.js +0 -11
- package/packages/src-/helpers/my/Test3.js +0 -11
- package/packages/src-/helpers/my/Test4.js +0 -11
- package/packages/src-/models/Jubu.js +0 -29
- package/packages/src-/models/Jubu2.js +0 -20
- package/packages/src-/models/Map_master.js +0 -22
- package/packages/src-/models/Test.js +0 -29
- package/packages/src-/models/Test2.js +0 -29
- package/packages/src-/models/User2Sequelize.js +0 -23
- package/packages/src-/models/Users-sqlite.js +0 -21
- package/packages/src-/models/Users.js +0 -53
- package/packages/src-/models/Uuuuuxxx.js +0 -23
- package/packages/src-/models/xxx/Uuuuuxxx.js +0 -23
- /package/packages/cli/core/generator/{_basic-helpers → _helpers_basic} +0 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
const logUpdate = require("log-update");
|
|
2
|
+
const emoji = require('node-emoji')
|
|
3
|
+
const { DeHashIt, M, X } = require(__dirname + "/../helpers/math");
|
|
4
|
+
const Sequelize = require('sequelize');
|
|
5
|
+
let testSql = {};
|
|
6
|
+
|
|
7
|
+
function filterDbIsTrue(dbConfig, cb) {
|
|
8
|
+
try {
|
|
9
|
+
let dbIsTrue = [];
|
|
10
|
+
dbConfig.filter((e, k) => {
|
|
11
|
+
if (e.is_connect) {
|
|
12
|
+
dbIsTrue.push(e);
|
|
13
|
+
}
|
|
14
|
+
if (dbConfig.length == k + 1) {
|
|
15
|
+
if(dbIsTrue.length) {
|
|
16
|
+
console.log('\n[102m[90m Pre-Flight [0m [0mTesting Database connection:');
|
|
17
|
+
}
|
|
18
|
+
cb(null, dbIsTrue);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
} catch (error) {
|
|
22
|
+
cb(error, null);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function testConnectInProcess (database_config, dbConnTotal, cb) {
|
|
27
|
+
try {
|
|
28
|
+
let val = database_config.shift();
|
|
29
|
+
if (val) {
|
|
30
|
+
initSequelize(val, async (err, sq) => {
|
|
31
|
+
if (err) {
|
|
32
|
+
console.error("[101m Failed [0m Can't to create a Sequelize instance:[36m", val.name, "[0m\n", err);
|
|
33
|
+
cb(err, null, null);
|
|
34
|
+
}
|
|
35
|
+
// Test connection
|
|
36
|
+
await sq.authenticate()
|
|
37
|
+
.then(() => {
|
|
38
|
+
// Database some is true perfectly.
|
|
39
|
+
if (database_config.length == 0) {
|
|
40
|
+
if (sq) {
|
|
41
|
+
testSql[ val.name ] = sq;
|
|
42
|
+
//console.log("DB true, Perfectly.", val.name);
|
|
43
|
+
cb(null, true, testSql);
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
testSql[ val.name ] = sq;
|
|
47
|
+
testConnectInProcess(database_config, dbConnTotal, cb);
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
.catch(err => {
|
|
51
|
+
console.error("[101m Failed [0m Unable to connect to the database:[36m", val.name, "[0m\n", err);
|
|
52
|
+
cb(err, null, null);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
} else if (!dbConnTotal) {
|
|
56
|
+
// All Database is falsly perfectly.
|
|
57
|
+
//console.log("DB all false, Perfectly.");
|
|
58
|
+
cb(null, true, testSql);
|
|
59
|
+
}
|
|
60
|
+
} catch (error) {
|
|
61
|
+
cb(error, null, null);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function disConnectTestDB(dbConfigTruthy, dbs, cb) {
|
|
66
|
+
try {
|
|
67
|
+
dbConfigTruthy.map((e, k) => {
|
|
68
|
+
// Closing database
|
|
69
|
+
if (dbs[ e.name ].close()) {
|
|
70
|
+
if (dbConfigTruthy.length == k + 1) {
|
|
71
|
+
cb(null, dbConfigTruthy);
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
cb(`Close database failed, ${e.name}`, null);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
} catch (error) {
|
|
78
|
+
cb(error, null);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function logit(msg, next = false) {
|
|
83
|
+
logUpdate(msg);
|
|
84
|
+
if(next) {
|
|
85
|
+
logUpdate.done();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function initSequelize(val, cb) {
|
|
90
|
+
try {
|
|
91
|
+
const promise = new Promise((resolve) => {
|
|
92
|
+
// check hash ?
|
|
93
|
+
if(val.username && val.password) {
|
|
94
|
+
if(val.username.length < 55 || val.password < 55) {
|
|
95
|
+
return cb("Error: No Hash access for connect to database.\n", null);
|
|
96
|
+
}
|
|
97
|
+
let accessDb = [];
|
|
98
|
+
[val.username, val.password].map((e, k) => {
|
|
99
|
+
DeHashIt(e.toString(), null, (17).toString().slice(0,-1).length, (err, d) => {
|
|
100
|
+
if(!err) {
|
|
101
|
+
accessDb.push(d.split("sh,")[1].split(M(X).toString().slice(0,2)+M(X).toString())[0].slice(0,-1));
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
if(k+1==2) {
|
|
105
|
+
resolve(accessDb);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
} else {
|
|
109
|
+
resolve([null, null]);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
Promise.all([promise]).then(final => {
|
|
113
|
+
// stdout pre-flight connection
|
|
114
|
+
logit(`- [91m[${val.dialect}] [0m[36m${val.name}[0m`);
|
|
115
|
+
logit(emoji.get('heavy_multiplication_x') + ` [91m[${val.dialect}] [0m[36m${val.name}[0m`);
|
|
116
|
+
// create connection
|
|
117
|
+
const sq = new Sequelize({
|
|
118
|
+
dialect: val.dialect || "mysql",
|
|
119
|
+
host: (val.host == "localhost" || val.host == "http://localhost") ? "127.0.0.1" : val.host,
|
|
120
|
+
username: final[0][0],
|
|
121
|
+
password: final[0][1],
|
|
122
|
+
database: val.database,
|
|
123
|
+
port: val.port,
|
|
124
|
+
storage: val.storage || ":memory:",
|
|
125
|
+
protocol: val.protocol || null,
|
|
126
|
+
logging: val.logging || false,
|
|
127
|
+
dialectOptions: {
|
|
128
|
+
socketPath: ((val.dialectOptions) ? ((val.dialectOptions.socketPath) ? val.dialectOptions.socketPath : "") : ""), //Applications/MAMP/tmp/mysql/mysql.sock
|
|
129
|
+
supportBigNumbers: ((val.dialectOptions) ? ((val.dialectOptions.supportBigNumbers) ? val.dialectOptions.supportBigNumbers : false) : false),
|
|
130
|
+
bigNumberStrings: ((val.dialectOptions) ? ((val.dialectOptions.bigNumberStrings) ? val.dialectOptions.bigNumberStrings : false) : false),
|
|
131
|
+
options: ((val.dialectOptions) ? ((val.dialectOptions.options) ? ({ encrypt: false, ...val.dialectOptions.options }) : { encrypt: false }) : { encrypt: false }),
|
|
132
|
+
},
|
|
133
|
+
omitNull: val.omitNull || false,
|
|
134
|
+
native: val.native || false,
|
|
135
|
+
define: {
|
|
136
|
+
underscored: ((val.define) ? ((val.define.underscored) ? val.define.underscored : false) : false),
|
|
137
|
+
freezeTableName: ((val.define) ? ((val.define.freezeTableName === false) ? val.define.freezeTableName : true) : true),
|
|
138
|
+
charset: ((val.define) ? ((val.define.charset) ? val.define.charset : "utf8") : "utf8"),
|
|
139
|
+
dialectOptions: {
|
|
140
|
+
collate: ((val.define) ? ((val.define.dialectOptions) ? ((val.define.dialectOptions.timestamps) ? val.define.dialectOptions.timestamps : "utf8_general_ci") : "utf8_general_ci") : "utf8_general_ci"),
|
|
141
|
+
},
|
|
142
|
+
timestamps: ((val.define) ? ((val.define.timestamps) ? val.define.timestamps : false) : false),
|
|
143
|
+
},
|
|
144
|
+
sync: {
|
|
145
|
+
force: ((val.sync) ? ((val.sync.force) ? val.sync.force : false) : false),
|
|
146
|
+
},
|
|
147
|
+
pool: {
|
|
148
|
+
max: ((val.pool) ? ((val.pool.max) ? val.pool.max : 5) : 5),
|
|
149
|
+
idle: ((val.pool) ? ((val.pool.idle) ? val.pool.idle : 30000) : 30000),
|
|
150
|
+
acquire: ((val.pool) ? ((val.pool.acquire) ? val.pool.acquire : 60000) : 60000),
|
|
151
|
+
},
|
|
152
|
+
isolationLevel: val.isolationLevel || "Transaction.ISOLATION_LEVELS.REPEATABLE_READ",
|
|
153
|
+
query: {
|
|
154
|
+
raw: ((val.query) ? ((val.query.raw) ? val.query.raw : true) : true),
|
|
155
|
+
nest: ((val.query) ? ((val.query.nest) ? val.query.nest : true) : true),
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
logit(emoji.get('heavy_check_mark') + ` [91m[${val.dialect}] [0m[36m${val.name}[0m`, true);
|
|
159
|
+
cb(false, sq);
|
|
160
|
+
}).catch(err => {
|
|
161
|
+
console.log(`[103m[90m Warning [0m[0m Connection name \`[93m${val.name}[0m\``, err);
|
|
162
|
+
});
|
|
163
|
+
} catch (error) {
|
|
164
|
+
cb(error, null);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
module.exports = { filterDbIsTrue, testConnectInProcess, disConnectTestDB }
|
|
@@ -1,18 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* file walk autoload all file
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
*/
|
|
5
5
|
exports.fileWalk = (files) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
try {
|
|
8
|
+
if (files.length) {
|
|
9
|
+
let route;
|
|
10
|
+
files.map((val, key) => {
|
|
11
|
+
let endpointFile = val.replace(".js", "");
|
|
12
|
+
try {
|
|
13
|
+
route = require(endpointFile);
|
|
14
|
+
if (route instanceof Error) {
|
|
15
|
+
console.log(out.message);
|
|
16
|
+
reject(error);
|
|
17
|
+
}
|
|
18
|
+
route.init();
|
|
19
|
+
if (files.length == key + 1) {
|
|
20
|
+
resolve(true);
|
|
21
|
+
}
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.log(error);
|
|
24
|
+
reject(error);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
resolve(true);
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.log(error);
|
|
32
|
+
reject(error);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
//const Users = require("@/models/Users");
|
|
2
|
+
//const CronJob = require("cron").CronJob;
|
|
2
3
|
|
|
3
4
|
exports.init = () => {
|
|
4
5
|
|
|
6
|
+
/**
|
|
7
|
+
* TO DO something.
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
|
|
5
11
|
//Users.findAll().then(console.log)
|
|
6
12
|
|
|
7
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Job schedule: seccod minute hour dayOfMonth month dayOfWeek
|
|
15
|
+
* Learn more: https://github.com/kelektiv/node-cron
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
//new CronJob("0 0 0 * * *", () => {
|
|
19
|
+
//Run job.
|
|
20
|
+
//}, null, true, "Asia/Bangkok");
|
|
8
21
|
|
|
9
|
-
}
|
|
22
|
+
};
|
|
@@ -1,86 +1,19 @@
|
|
|
1
|
+
const { Base } = require("beech-api");
|
|
1
2
|
{{requireSomething}}
|
|
2
3
|
exports.init = () => {
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
data.message = 'Got a GET request.';
|
|
14
|
-
|
|
15
|
-
// @return
|
|
16
|
-
res.json(data);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
//@POST
|
|
20
|
-
endpoint.post('{{endpoint}}', Credentials, (req, res) => {
|
|
21
|
-
/**
|
|
22
|
-
* @param Integer id
|
|
23
|
-
*
|
|
24
|
-
* @return json
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
let id = req.body.id;
|
|
28
|
-
let data = {};
|
|
29
|
-
data.code = 200;
|
|
30
|
-
data.message = 'Got a POST request.';
|
|
31
|
-
|
|
32
|
-
// @return
|
|
33
|
-
res.json(data);
|
|
4
|
+
// Initialize Base endpoint
|
|
5
|
+
Base([{{tables}}]); // It's like magic creating endpoints for you (CRUD)
|
|
6
|
+
|
|
7
|
+
// Example GET request
|
|
8
|
+
endpoint.get("/example-{{endpoint}}", Credentials, (req, res) => {
|
|
9
|
+
// @response
|
|
10
|
+
res.json({
|
|
11
|
+
code: 200,
|
|
12
|
+
message: "Got a GET example request.",
|
|
13
|
+
});
|
|
34
14
|
});
|
|
15
|
+
|
|
16
|
+
// Your more request...
|
|
17
|
+
// Create more Endpoints, Learn more: https://github.com/bombkiml/beech-api?tab=readme-ov-file#endpoint
|
|
35
18
|
|
|
36
|
-
|
|
37
|
-
endpoint.put('{{endpoint}}/:id', Credentials, (req, res) => {
|
|
38
|
-
/**
|
|
39
|
-
* @param Integer id
|
|
40
|
-
*
|
|
41
|
-
* @return json
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
let id = req.params.id;
|
|
45
|
-
let data = {};
|
|
46
|
-
data.code = 200;
|
|
47
|
-
data.message = 'Got a PUT request at {{endpoint}}/' + id;
|
|
48
|
-
|
|
49
|
-
// @return
|
|
50
|
-
res.json(data);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
//@PATCH
|
|
54
|
-
endpoint.patch('{{endpoint}}/:id', Credentials, (req, res) => {
|
|
55
|
-
/**
|
|
56
|
-
* @param Integer id
|
|
57
|
-
*
|
|
58
|
-
* @return json
|
|
59
|
-
*/
|
|
60
|
-
|
|
61
|
-
let id = req.params.id;
|
|
62
|
-
let data = {};
|
|
63
|
-
data.code = 200;
|
|
64
|
-
data.message = 'Got a PATCH request at {{endpoint}}/' + id;
|
|
65
|
-
|
|
66
|
-
// @return
|
|
67
|
-
res.json(data);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
//@DELETE
|
|
71
|
-
endpoint.delete('{{endpoint}}/:id', Credentials, (req, res) => {
|
|
72
|
-
/**
|
|
73
|
-
* @param Integer id
|
|
74
|
-
*
|
|
75
|
-
* @return json
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
let id = req.params.id;
|
|
79
|
-
let data = {};
|
|
80
|
-
data.code = 200;
|
|
81
|
-
data.message = 'Got a DELETE request at {{endpoint}}/' + id;
|
|
82
|
-
|
|
83
|
-
// @return
|
|
84
|
-
res.json(data);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{{requireSomething}}
|
|
2
|
+
exports.init = () => {
|
|
3
|
+
|
|
4
|
+
// Initiate with Basic request currently support GET, POST, PUT, PATCH and DELETE
|
|
5
|
+
// Create Endpoint, Learn more: https://github.com/bombkiml/beech-api?tab=readme-ov-file#endpoints
|
|
6
|
+
|
|
7
|
+
endpoint.get("{{endpoint}}", Credentials, (req, res) => {
|
|
8
|
+
// @return
|
|
9
|
+
res.json({
|
|
10
|
+
code: 200,
|
|
11
|
+
message: "Got a GET request.",
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
endpoint.post("{{endpoint}}", Credentials, (req, res) => {
|
|
16
|
+
let id = req.body.id;
|
|
17
|
+
let name = req.body.name;
|
|
18
|
+
// @return
|
|
19
|
+
res.json({
|
|
20
|
+
code: 200,
|
|
21
|
+
result: {
|
|
22
|
+
id,
|
|
23
|
+
name,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
endpoint.put("{{endpoint}}/:id", Credentials, (req, res) => {
|
|
29
|
+
let id = req.params.id;
|
|
30
|
+
// @return
|
|
31
|
+
res.json({
|
|
32
|
+
code: 200,
|
|
33
|
+
message: "Got a PUT request at {{endpoint}}/" + id,
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// More request...
|
|
38
|
+
|
|
39
|
+
};
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
|
|
2
2
|
Usage:
|
|
3
|
-
$ beech [options] [arguments]
|
|
3
|
+
$ beech [options] [arguments] [special]
|
|
4
4
|
|
|
5
5
|
Options:
|
|
6
|
-
|
|
7
|
-
-v, --version
|
|
6
|
+
?, -h, --help Display this help message.
|
|
7
|
+
-v, --version Display the application version.
|
|
8
8
|
|
|
9
9
|
The following commands are available:
|
|
10
10
|
|
|
11
|
-
$ beech make <endpoint>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
$ beech make <model> --model Create a new Models file.
|
|
15
|
-
$ beech make <helper> --helper
|
|
16
|
-
$ beech passport init
|
|
17
|
-
$ beech add-on init
|
|
18
|
-
|
|
11
|
+
$ beech make <endpoint> Create a new Endpoints and unit test file,
|
|
12
|
+
You might using [special] `-R, --require`
|
|
13
|
+
for choose Model(s) used to endpoint file.
|
|
14
|
+
$ beech make <model> -M, --model Create a new Models file.
|
|
15
|
+
$ beech make <helper> --helper Create a new Helpers file.
|
|
16
|
+
$ beech passport init Initialize authentication with passport-jwt.
|
|
17
|
+
$ beech add-on init Initialize add-on file.
|
|
18
|
+
$ beech key:generate, key:gen Re-Generate application key (Dangerous!).
|
|
19
|
+
$ beech hash:<text> Hash text for Access to Database connection.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
Usage:
|
|
3
|
+
$ beech-app create <app-name>
|
|
4
|
+
$ beech-app update [arguments]
|
|
5
|
+
|
|
6
|
+
Options:
|
|
7
|
+
?, -h, --help Display this help message.
|
|
8
|
+
-v, --version Display the application version.update
|
|
9
|
+
|
|
10
|
+
Arguments:
|
|
11
|
+
-g, --global Global upgrade The beech-api to latest version.
|
|
@@ -1,23 +1,28 @@
|
|
|
1
|
-
const {
|
|
2
|
-
|
|
1
|
+
const { Schema } = require("beech-api");
|
|
2
|
+
// {{modelNameUppercase}} structure
|
|
3
|
+
const {{modelNameUppercase}} = Schema(sql.{{dbSelected}}).define("{{modelName}}", {
|
|
4
|
+
{{modelName}}_id: {
|
|
5
|
+
field: "id",
|
|
3
6
|
type: DataTypes.INTEGER,
|
|
4
7
|
autoIncrement: true,
|
|
5
8
|
primaryKey: true,
|
|
6
9
|
},
|
|
7
|
-
examField1: DataTypes.STRING, //
|
|
10
|
+
examField1: DataTypes.STRING, // Asign more DataTypes, Learn more: https://sequelize.org/docs/v6/core-concepts/model-basics/#data-types
|
|
8
11
|
examField2: DataTypes.DATE,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return {{modelNameUppercase}}.findOne({ where: { id: id } });
|
|
12
|
+
examField3: {
|
|
13
|
+
type: DataTypes.STRING,
|
|
14
|
+
allowNull: false,
|
|
15
|
+
// set(value) {
|
|
16
|
+
// this.setDataValue("examField3", md5(value));
|
|
17
|
+
// },
|
|
16
18
|
},
|
|
19
|
+
createdAt: DataTypes.DATE,
|
|
20
|
+
updatedAt: DataTypes.DATE,
|
|
21
|
+
});
|
|
17
22
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
// Example basic function Get one data by id
|
|
24
|
+
function exampleFindOne{{modelNameUppercase}}ById(id) {
|
|
25
|
+
return {{modelNameUppercase}}.findOne({ where: { id: id } });
|
|
26
|
+
}
|
|
22
27
|
|
|
23
|
-
}
|
|
28
|
+
module.exports = { {{modelNameUppercase}}, exampleFindOne{{modelNameUppercase}}ById };
|
|
@@ -12,13 +12,11 @@ module.exports = {
|
|
|
12
12
|
// Example basic function get data from table {{modelName}}
|
|
13
13
|
findAll() {
|
|
14
14
|
return new Promise((resolve, reject) => {
|
|
15
|
-
|
|
16
15
|
// call sql.{{dbSelected}} database connection name.
|
|
17
16
|
sql.{{dbSelected}}.query("SELECT * FROM {{modelName}}", (err, results) => {
|
|
18
17
|
if (err) reject(err);
|
|
19
18
|
resolve(results);
|
|
20
19
|
});
|
|
21
|
-
|
|
22
20
|
});
|
|
23
21
|
}
|
|
24
22
|
|
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
"name": "application",
|
|
3
3
|
"version": "0.1.0",
|
|
4
4
|
"description": "The project is powered by Beech API framework",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"main": "index.js",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"start": "beech-service serve",
|
|
8
9
|
"test": "node ./node_modules/jest/bin/jest __tests__ -o --watch --config"
|
|
9
10
|
},
|
|
10
11
|
"dependencies": {
|
|
11
|
-
"beech-api": "^3.
|
|
12
|
+
"beech-api": "^3.7.0"
|
|
12
13
|
},
|
|
13
14
|
"devDependencies": {
|
|
14
|
-
"jest": "^
|
|
15
|
+
"jest": "^28.1.3"
|
|
15
16
|
}
|
|
16
|
-
}
|
|
17
|
+
}
|