4

I am trying to learn how to work with KrakenJs and use mysql for my database. but I have not been able to find anything on line , this is what i have come up with so far I have created a folder called lib and I want to have my connection file db.js to the database

'use strict';

var mysql = require('mysql');
var Sequelize = require('sequelize');

var sequelize = new Sequelize('site', 'root', 'root', {
  host: 'localhost',
  dialect: 'mysql',

  pool: {
    max: 5,
    min: 0,
    idle: 10000
},

});


module.exports = sequelize;

first of all I am not sure what needs to go my main index.js file config option part ...

'use strict';

var express = require('express');
var kraken = require('kraken-js');
var db = require('./lib/db');

var options, app;

/*
 * Create and configure application. Also exports application instance     for use by tests.
 * See https://github.com/krakenjs/kraken-js#options for additional configuration options.
 */
options = {
    onconfig: function (config, next) {
        /*
         * Add any additional config setup or overrides here. `config` is an initialized
         * `confit` (https://github.com/krakenjs/confit/) configuration object.
         */
           next(null, config);
      }
};

How to set up my model , this is just a simple model , I just wanna get the idea of how to use it ...

'use strict';

var db = require('../lib/db');

module.exports = function User() {

   var User = sequelize.define('user', {
    firstName: {
        type: Sequelize.STRING,
    },
    lastName: {
        type: Sequelize.STRING
    }
    }, {
    freezeTableName: true // Model tableName will be the same as the   model name
    });

};

and Lastly how to use it my controller

'use strict';

var User = require('../models/users');


module.exports = function (router) {

// var model = new User();

router.get('/', function (req, res) {

    User.findOne().then(function (user) {
            res.render('index', user);

        });



    });

};
CYBERSIX
  • 347
  • 1
  • 7
  • 19

0 Answers0