Installed knex and built a basic create article endpoint
parent
6798039f32
commit
0ac1e61e4b
@ -0,0 +1,9 @@
|
||||
var config = require('./knexfile.js'); //requiring the knexfile that contains our connection object.
|
||||
var env = 'development'; // specify the config enviroment
|
||||
var knex = require('knex')(config[env]); // imports knex with our connection object (found in knexfile).
|
||||
|
||||
// Export the knex library for use. All knex commands remain the same.
|
||||
module.exports = knex;
|
||||
|
||||
// Run the latest DB migrations whenever the server starts.
|
||||
knex.migrate.latest([config]);
|
Binary file not shown.
@ -0,0 +1,16 @@
|
||||
module.exports = {
|
||||
development: {
|
||||
client: 'sqlite3',
|
||||
connection: {
|
||||
filename: "./db/matterwiki.sqlite"
|
||||
},
|
||||
useNullAsDefault: true,
|
||||
debug: true
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
The development object is the connection object for the development database.
|
||||
We need to create more for different environments (production, testing, staging).
|
||||
This environment is being used in the db.js file in the root directory. Check there.
|
||||
*/
|
@ -0,0 +1,13 @@
|
||||
|
||||
exports.up = function(knex, Promise) {
|
||||
return knex.schema.createTable('articles', function (table) {
|
||||
table.increments();
|
||||
table.string('title');
|
||||
table.text('body');
|
||||
table.timestamps();
|
||||
})
|
||||
};
|
||||
|
||||
exports.down = function(knex, Promise) {
|
||||
|
||||
};
|
Loading…
Reference in New Issue