biggora / caminte

Cross-db ORM for NodeJS
http://www.camintejs.com/
MIT License
1.08k stars 119 forks source link

MYSQL auto create #128

Open edeuxk opened 7 years ago

edeuxk commented 7 years ago

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.

aryeharmon commented 7 years ago

@edeuxk did you figure this out?

aryeharmon commented 7 years ago

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 commented 7 years ago

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