{"id":22443016,"url":"https://github.com/veltzer/demos-lang-js-loopback","last_synced_at":"2026-04-07T05:31:46.385Z","repository":{"id":35027503,"uuid":"39136542","full_name":"veltzer/demos-loopback","owner":"veltzer","description":"A working example of loopback for node.js","archived":false,"fork":false,"pushed_at":"2024-09-11T09:14:24.000Z","size":116,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-09-11T12:28:48.385Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/veltzer/demos-loopback","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"hotei/ansiterm","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/veltzer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-07-15T12:51:13.000Z","updated_at":"2024-09-11T09:14:36.000Z","dependencies_parsed_at":"2024-06-15T09:48:19.463Z","dependency_job_id":"4e8115a2-bbc7-444b-89cf-2c48766ac558","html_url":"https://github.com/veltzer/demos-loopback","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veltzer%2Fdemos-loopback","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veltzer%2Fdemos-loopback/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veltzer%2Fdemos-loopback/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veltzer%2Fdemos-loopback/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/veltzer","download_url":"https://codeload.github.com/veltzer/demos-loopback/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228398665,"owners_count":17913661,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-06T02:21:57.727Z","updated_at":"2026-04-07T05:31:46.334Z","avatar_url":"https://github.com/veltzer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"#loopback-example-mysql\n\nBasic instructions:\n\n```\n$ git clone https://github.com/strongloop/loopback-example-mysql.git\n$ cd loopback-example-mysql\n$ npm install\n```\n\nThen run any script in `server/bin` (for example, `node server/bin/discover-schema.js`).\n\n##Prerequisites\n\n###Tutorials\n\n- [Getting started with LoopBack](http://docs.strongloop.com/display/LB/Getting+started+with+LoopBack)\n\n###Knowledge\n- [LoopBack models](http://docs.strongloop.com/display/LB/Defining+models)\n\n##Procedure\n\n###Create the application\n\n####Application information\n\n- Name: `loopback-example-mysql`\n- Directory to contain the project: `loopback-example-mysql`\n\n```\n$ slc loopback loopback-example-mysql\n... # follow the prompts\n$ cd loopback-example-mysql\n```\n\n###Install the connector\n\n```\n$ npm install --save loopback-connector-mysql\n```\n\n###Configure the datasource\n\n####Datasource information\n- Datasource: `accountDs`\n- Connector: `MySQL`\n\n```\n$ slc loopback:datasource accountDs\n... # follow the prompts\n```\n\nAdd the [datasource configurations](/server/datasources.json#L9-L13) to\n[`server/datasources.json`](/server/datasources.json).\n\n\u003e We provide a demo server for convenience sake, but feel free to use your own database server.\n\n###Add a model\n\n####Model information\n- Name: `Account`\n  - Datasource: `accountDs`\n  - Base class: `PersistedModel`\n  - Expose via REST: `Yes`\n  - Custom plural form: *Leave blank*\n  - Properties\n    - `email`\n      - String\n      - Not required\n    - `createdAt`\n      - Date\n      - Not required\n    - `lastModifiedAt`\n      - Date\n      - Not required\n\n```\n$ slc loopback:model Account\n... # follow the prompts\n```\n\n###Add a script to migrate data\n\nCreate a directory for to store scripts.\n\n```\n$ mkdir server/bin\n```\n\nCreate [`automigrate.js`](/server/bin/automigrate.js) inside the\n[`bin`](/server/bin) directory.\n\n\u003e [`datasSource.automigrate()`](/server/bin/automigrate.js) requires INSERT object, CREATE DDL, and DROP DDL rights to execute properly.\n\n####Test the script\n\n\u003e #####WARNING\n\u003e [`dataSource.automigrate()`](/server/bin/automigrate.js#L18) creates a new table in the database if it doesn't exist. If the table already exists, it is **destroyed** and **all** existing data is dropped. If you want to keep the existing data, use `datasource.autoupdate()` instead.\n\n```\n$ node server/bin/automigrate.js\n```\n\nThis script creates [two models](/server/bin/automigrate.js#L5-L14) in the\n[specified data source](/server/bin/automigrate.js#L16).\n\n\u003e You can view the newly inserted data using built-in [API explorer](http://docs.strongloop.com/display/LB/Use+API+Explorer). Start the application with `slc run` and browse to [`localhost:3000/explorer`][explorer] to inspect the data.\n\n###Add a script to discover a schema\n\n\u003e *Discovery* is the process of reverse engineering a LoopBack model from an existing database schema.\n\nCreate [`discover-schema.js`](/server/bin/discover-schema.js) inside the\n[`bin` directory](/server/bin).\n\n####Test the script\n\n```\n$ node server/bin/discover-schema.js\n```\n\nYou should see:\n\n```\n{\n  \"name\": \"Account\",\n  \"options\": {\n    \"idInjection\": false,\n    \"mysql\": {\n      \"schema\": \"loopback-example-mysql\",\n      \"table\": \"Account\"\n    }\n  },\n  \"properties\": {\n    \"id\": {\n      \"type\": \"Number\",\n      \"required\": true,\n      \"length\": null,\n      \"precision\": 10,\n      \"scale\": 0,\n      \"id\": 1,\n      \"mysql\": {\n        \"columnName\": \"id\",\n        \"dataType\": \"int\",\n        \"dataLength\": null,\n        \"dataPrecision\": 10,\n        \"dataScale\": 0,\n        \"nullable\": \"N\"\n      }\n    },\n    \"email\": {\n      \"type\": \"String\",\n      \"required\": false,\n      \"length\": 1536,\n      \"precision\": null,\n      \"scale\": null,\n      \"mysql\": {\n        \"columnName\": \"email\",\n        \"dataType\": \"varchar\",\n        \"dataLength\": 1536,\n        \"dataPrecision\": null,\n        \"dataScale\": null,\n        \"nullable\": \"Y\"\n      }\n    },\n    \"createdat\": {\n      \"type\": \"Date\",\n      \"required\": false,\n      \"length\": null,\n      \"precision\": null,\n      \"scale\": null,\n      \"mysql\": {\n        \"columnName\": \"createdAt\",\n        \"dataType\": \"datetime\",\n        \"dataLength\": null,\n        \"dataPrecision\": null,\n        \"dataScale\": null,\n        \"nullable\": \"Y\"\n      }\n    },\n    \"lastmodifiedat\": {\n      \"type\": \"Date\",\n      \"required\": false,\n      \"length\": null,\n      \"precision\": null,\n      \"scale\": null,\n      \"mysql\": {\n        \"columnName\": \"lastModifiedAt\",\n        \"dataType\": \"datetime\",\n        \"dataLength\": null,\n        \"dataPrecision\": null,\n        \"dataScale\": null,\n        \"nullable\": \"Y\"\n      }\n    }\n  }\n}\n```\n\n###Add a script to discover and build models\n\nCreate [`discover-and-build.js`](/server/bin/discover-and-build.js) in the\n[`bin` directory](/server/bin).\n\n####Test the script\n\n```\n$ node server/bin/discover-and-build.js\n```\n\nYou should see:\n\n```\n[ { id: 1,\n    email: 'foo@bar.com',\n    createdat: Tue Jan 06 2015 14:09:16 GMT-0800 (PST),\n    lastmodifiedat: Tue Jan 06 2015 14:09:16 GMT-0800 (PST) },\n  { id: 2,\n    email: 'baz@qux.com',\n    createdat: Tue Jan 06 2015 14:09:16 GMT-0800 (PST),\n    lastmodifiedat: Tue Jan 06 2015 14:09:16 GMT-0800 (PST) } ]\n```\n\n\u003e Your `createdat` and `lastmodifiedat` dates will be different.\n\nThe resulting objects are fully functional\n[LoopBack models](/server/bin/discover-and-build.js#L7) and thus contain all the\nfeatures provided by LoopBack such as\n[`find()`](/server/bin/discover-and-build.js#L10), and so on.\n\n---\n\n- [Next tutorial][next-tutorial]\n- [All tutorials][all-tutorials]\n\n[all-tutorials]: https://github.com/strongloop/loopback-example\n[explorer]: http://localhost:3000/explorer\n[localhost]: http://localhost:3000\n[next-tutorial]: https://github.com/strongloop/loopback-example-model-relations\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fveltzer%2Fdemos-lang-js-loopback","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fveltzer%2Fdemos-lang-js-loopback","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fveltzer%2Fdemos-lang-js-loopback/lists"}