@shagital/adonisjs-seeder-generator
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "@shagital/adonisjs-seeder-generator", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "An AdonisJS (nodejs) package to generate seeder files from existing DB table data", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -65,2 +65,57 @@ # AdonisJS Seeder Generator | ||
## Example Seeder file | ||
```js | ||
'use strict'; | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| CitiesSeeder | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Make use of the Factory instance to seed database with dummy data or | ||
| make use of Lucid models directly. | ||
| | ||
*/ | ||
const Database = use('Database'); | ||
class CitiesSeeder { | ||
async run () { | ||
await Database.connection('mysql').table('cities').truncate(); | ||
let data = [ | ||
{ | ||
"id": 219, | ||
"name": "Kuçovë", | ||
"country_id": 3, | ||
"state_id": 629, | ||
"country_code": "AL", | ||
"state_code": "BR", | ||
"latitude": 40.80028, | ||
"longitude": 19.91667 | ||
}, | ||
{ | ||
"id": 280, | ||
"name": "Çorovodë", | ||
"country_id": 3, | ||
"state_id": 629, | ||
"country_code": "AL", | ||
"state_code": "BR", | ||
"latitude": 40.50417, | ||
"longitude": 20.22722 | ||
} | ||
... | ||
]; | ||
var i, j, temparray, chunk = 1000; | ||
for (i = 0,j = data.length; i < j; i += chunk) { | ||
temparray = data.slice(i, i+chunk); | ||
await Database.connection('mysql').table('cities').insert(temparray); | ||
} | ||
} | ||
} | ||
module.exports = CitiesSeeder; | ||
``` | ||
## Changelog | ||
@@ -67,0 +122,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23145
139