Skip to content

Instantly share code, notes, and snippets.

@vjefri
Forked from nsipplswezey/1. Command Line
Last active June 5, 2016 02:38
Show Gist options
  • Save vjefri/7e99c258f627cf41ebe8886f602ce0a5 to your computer and use it in GitHub Desktop.
Save vjefri/7e99c258f627cf41ebe8886f602ce0a5 to your computer and use it in GitHub Desktop.
Nodal TL:DR Seed Database
npm install -g nodal
nodal new todo-pgjson
cd todo-pgjson
nodal g:model Todo user_id:int tasks:json done:boolean
nodal g:controller --for Todos
nodal db:bootstrap
// add json data to seed.json
nodal db:seed
nodal db:bootstrap
// config/seed.json
{
"development": {
"Todo": [
{
"user_id" : "1",
"done" : "false",
"tasks" : {"grapes":"7","bananas":"4","apples":"3"}
}
]
},
"test": {
"Todo": [
{
"user_id" : "1",
"done" : "false",
"tasks" : {"grapes":"7","bananas":"4","apples":"3"}
}
]
},
"production": {}
}
Request:
GET to /todos
Response:
{
"meta": {
"total": 2,
"count": 2,
"offset": 0,
"error": null
},
"data": [
{
"id": 1,
"user_id": 1,
"tasks": {
"apples": "3",
"grapes": "7",
"bananas": "4"
},
"done": false,
"created_at": "2016-06-05T02:34:06.291Z",
"updated_at": "2016-06-05T02:34:06.291Z"
},
{
"id": 2,
"user_id": 1,
"tasks": {
"apples": "3",
"grapes": "7",
"bananas": "4"
},
"done": false,
"created_at": "2016-06-05T02:34:09.730Z",
"updated_at": "2016-06-05T02:34:09.730Z"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment