Need help on populating a table #1433
Answered
by
jrishabh55
FashMuyhee
asked this question in
Help
-
Hi guys, i want to know if there is a means of populating a table using database seeder with a custom data not a faker |
Beta Was this translation helpful? Give feedback.
Answered by
jrishabh55
Aug 10, 2020
Replies: 1 comment 1 reply
-
Seeds as described in the docs are just classes with run method. You can put any database related queries in them, You can use seeds to upload your custom data https://adonisjs.com/docs/4.1/seeds-and-factories#_seeds I think you are confusing seeds with factories. Factories are an additional resource you can use to create dummy data, You should be able to use seeds alone to upload the data const Factory = use('Factory')
const Database = use('Database')
// Get your data from a json file or hardcode it like below
class UserSeeder {
async run () {
await Database
.from('users')
.insert([{username: 'foo'}, {username: 'bar'}])
}
}
module.exports = UserSeeder |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
FashMuyhee
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seeds as described in the docs are just classes with run method. You can put any database related queries in them, You can use seeds to upload your custom data
https://adonisjs.com/docs/4.1/seeds-and-factories#_seeds
I think you are confusing seeds with factories. Factories are an additional resource you can use to create dummy data, You should be able to use seeds alone to upload the data