caminte icon indicating copy to clipboard operation
caminte copied to clipboard

MYSQL auto create

Open edeuxk opened this issue 8 years ago • 3 comments

Hi,

I would like to know if there is any parameters that I have to add on the caminte constructor to auto create SQL Tables if they are not created?

Thank you.

edeuxk avatar Dec 16 '16 14:12 edeuxk

@edeuxk did you figure this out?

aryeharmon avatar May 29 '17 11:05 aryeharmon

figured it out.

var caminte = require('caminte');
var Schema = caminte.Schema;

config = {
     driver     : "mysql",    // or mariadb
    ...........
};

var schema = new Schema(config.driver, config);

var Post = schema.define('Post', {
    title:     { type: schema.String,  limit: 255 },
    content:   { type: schema.Text },
    params:    { type: schema.JSON },
    date:      { type: schema.Date,    default: Date.now },
    published: { type: schema.Boolean, default: false, index: true }
});

schema.adapter.automigrate(function() {
    console.log('done auto migrating!!!');
});

aryeharmon avatar May 29 '17 13:05 aryeharmon

if you want to update the schema without droping and creating a new table when you change fields, use: schema.adapter.autoupdate(function() {})

aryeharmon avatar May 29 '17 14:05 aryeharmon