bhoriuchi / bookshelf-factory Goto Github PK
View Code? Open in Web Editor NEWCreate deeply nested bookshelf models with CRUD functions from JSON definitions
Create deeply nested bookshelf models with CRUD functions from JSON definitions
create database b_fac;
use b_fac;
create table posts (id int(11) auto_increment , name varchar(100), primary key(id));
create table tags (id int(11) auto_increment , slug varchar(100), primary key(id));
create table posts_tags(id int(11) auto_increment, post_id int(11), tag_id int(11), primary key(id), foreign key (post_id) references posts(id), foreign key (tag_id) references tags(id));
insert into posts (name) values ('eins');
var config = {
"client": "mysql",
"connection": {
"host": "127.0.0.1",
"user": "root",
"password": "",
"database": "b_fac",
"charset": "utf8"
}
};
// require the package and pass the db connection config
var factory = require('bookshelf-factory')(config);
var type = factory.schemer.constants.type;
// define a schema in schemer format
// in this example survivor.id has the views extended property that defines
// views that property belongs to. survivor.groups also has the extended
// property belongsToMany and specifies the model to use for the relationship
var schema = {
posts: {
id: {type: type.string},
name: {type: type.string, size: 200},
tags: {belongsToMany: 'tags', junction: 'posts_tags', foreignKey: 'post_id', otherKey: 'tag_id'},
},
tags: {
id: {type: type.string},
slug: {type: type.string, size: 100}
},
posts_tags: {
id: {type: type.string},
post_id: {type: type.string},
tag_id: {type: type.string}
}
};
// call the create function to create all the models
var models = factory.create(schema);
// forge the model and get all of its resources
models.posts.forge().getResources().then(function (results) {
// pretty print the results to the console
console.log(JSON.stringify(results, null, ' '));
});
I am getting
Unhandled rejection Error: ER_BAD_FIELD_ERROR: Unknown column 'tags.null' in 'on clause'
relations will be correct on initial save but not on an update
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.