Skip to content
This repository was archived by the owner on Jan 20, 2020. It is now read-only.

Commit 21327e9

Browse files
author
Luciano Nooijen
committed
Added first bit of the module exposed API
1 parent 7c952ab commit 21327e9

File tree

7 files changed

+57
-1
lines changed

7 files changed

+57
-1
lines changed

helpers/generate-knex-config.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const generateKnexConfig = (client, host, database, user, password, debug) => {
2+
const config = {
3+
client,
4+
connection: {
5+
host,
6+
database,
7+
user,
8+
password,
9+
},
10+
pool: {
11+
min: 2,
12+
max: 10,
13+
},
14+
migrations: {
15+
tableName: 'knex_migrations',
16+
},
17+
debug,
18+
asyncStackTraces: debug,
19+
};
20+
21+
return config;
22+
};
23+
24+
module.exports = generateKnexConfig;

helpers/helpers.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* eslint-disable global-require */
2+
3+
module.exports = {
4+
knex: require('./database'),
5+
logger: require('./logger'),
6+
generateKnexConfig: require('./generate-knex-config'),
7+
};

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./src');

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nodejs-blog",
33
"version": "0.0.3",
44
"description": "A blog API built in NodeJS that can be used as a standalone application, or included in a NodeJS application",
5-
"main": "server.js",
5+
"main": "index.js",
66
"author": "Luciano Nooijen <luciano@bytecode.nl> (https://bytecode.nl)",
77
"license": "GPL-3.0-only",
88
"private": false,

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./nodejs-blog');

src/nodeblog-class.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// TODO: Make this work and stuff
2+
3+
const getKnexInstance = require('knex');
4+
const { generateKnexConfig } = require('../helpers');
5+
6+
class NodeBlog {
7+
constructor(client, host, database, user, password, debug) {
8+
this.client = client;
9+
this.host = host;
10+
this.database = database;
11+
this.user = user;
12+
this.password = password;
13+
this.debug = debug;
14+
this.knexConfig = { client, host, database, user, password, debug }; // eslint-disable-line
15+
this.knex = getKnexInstance(generateKnexConfig);
16+
this.knex.migrate.latest(); // TODO: Clean up
17+
}
18+
}
19+
20+
module.exports = NodeBlog;

src/nodejs-blog.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const getNodeBlogInstance = require('./nodeblog-class');
2+
3+
module.exports = getNodeBlogInstance;

0 commit comments

Comments
 (0)