Skip to content

Commit

Permalink
Create Datebase seeder
Browse files Browse the repository at this point in the history
  • Loading branch information
a632079 committed Jan 29, 2018
1 parent 4c78331 commit e54909b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class db {
} else {
// Register Model
const modelArray = require(path.join(__dirname, '../', './src/models/databases', model))
console.log(modelArray[1])
this[model] = this.sequelize.define(model, modelArray[0], modelArray[1])
return this[model]
}
Expand Down
31 changes: 31 additions & 0 deletions test/generateDate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const preStart = require('./prestart')
preStart.load()
const db = require('./db')
function randomString (len) {
len = len || 32
const chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
const maxPos = chars.length
let pwd = ''
for (i = 0; i < len; i++) {
pwd += chars.charAt(Math.floor(Math.random() * maxPos))
}
return pwd
}
async function generateDate () {
const hitokoto = await db.registerModel('hitokoto')
// Generate 100 data
for (let index = 0; index < 100; index++) {
hitokoto.create({
hitokoto: randomString(20),
type: 'c',
from: 'test',
creator: 'hitokoto',
owner: 'hitokoto'
})
.catch(err => {
console.log(err)
process.exit(1)
})
}
}
generateDate()

0 comments on commit e54909b

Please sign in to comment.