Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const connection = {
- client: 'pg',
- connection: {
- host : process.env.HOST,
- user : process.env.USER,
- password : process.env.PASSWORD,
- database : process.env.DATABASE
- },
- pool: { min: 1, max: 10 },
- debug: false
- };
- const knex = require('knex')(connection);
- const TABLE_TODO = 'todo';
- module.exports.createTodoTable = async (event, context) => {
- if(await knex.schema.hasTable(TABLE_TODO)){
- return response(403, 'Table '+ TABLE_TODO+ ' already exist');
- }
- const table = await knex.schema.createTable(TABLE_TODO, function(table) {
- table.increments('id').primary();
- table.string('text');
- table.dateTime("created_at").defaultTo(knex.fn.now());
- table.dateTime("updated_at");
- table.dateTime("deleted_at");
- });
- return response(200,table);
- };
- module.exports.addToTodoTable = async (event, context) => {
- if(!await knex.schema.hasTable(TABLE_TODO)){
- return response(403, 'Table '+ TABLE_TODO+ ' not exist');
- }
- const table = await knex(TABLE_TODO).insert([{
- text: 'Hello, This is my first note',
- }])
- return response(200,table);
- };
- function response(statusCode, body) {
- return {
- statusCode: statusCode,
- body: JSON.stringify(body),
- }
- };
Add Comment
Please, Sign In to add comment