Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way for converting SQL to node-orm2 Model #260

Closed
hoseinmobasher opened this issue Jul 31, 2013 · 2 comments
Closed

Any way for converting SQL to node-orm2 Model #260

hoseinmobasher opened this issue Jul 31, 2013 · 2 comments

Comments

@hoseinmobasher
Copy link

Hello,
I am beginner in node-orm2. I want to know any way to convert my sql table code to node-orm2 model.

Please introduce a way to convert? Should i do it with self programming, or node-orm2 has any tools.

Cheers,
Hossein

@dresende
Copy link
Owner

It does not have any tools yet to do it. You always have to define your models and they don't need to be exactly as your tables (the column types and sizes). Perhaps you're talking about something like #103 . Here's an example:

CREATE TABLE `cats` (
    `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(50) DEFAULT "Garfield",
    `breed` VARCHAR(100),
    PRIMARY KEY (`id`)
);

You can just define a model like this (no need to sync):

var Cat = db.define('cats', {
    name : { type: "text", defaultValue: "Garfield" },
    breed : String // you can use native types if no options needed
});

It assumes id column as primary key automatically.

@hoseinmobasher
Copy link
Author

This is good idea to use SQL and node-orm2 together. 👍

Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants