knex-seed
v1.0.1
Published
Helper function to insert or update seed data with ease using knex
Downloads
19
Maintainers
Readme
knex-seed
Helper function to insert or update seed data with ease using knex.
Installation
npm i knex-seed
Usage Example
import { Knex } from 'knex'
import { seedRow } from 'knex-seed'
export async function seed(knex: Knex): Promise<void> {
let teacher_alice_id = await seedRow(
knex,
'teacher',
{ email: '[email protected]' },
{ name: 'Alice', course: 'Yoga' },
)
await seedRow(
knex,
'student',
{ tel: '98765432' },
{ name: 'Bob', teacher_id: teacher_alice_id },
)
await seedRow(
knex,
'student',
{ tel: '65432198' },
{ name: 'Charlie', teacher_id: teacher_alice_id },
)
}
Typescript Signature
import { Knex } from 'knex'
export function seedRow(
knex: Knex,
table: string,
filter: object,
extraData?: object,
): Promise<number>
License
This project is licensed with BSD-2-Clause
This is free, libre, and open-source software. It comes down to four essential freedoms [ref]:
- The freedom to run the program as you wish, for any purpose
- The freedom to study how the program works, and change it so it does your computing as you wish
- The freedom to redistribute copies so you can help others
- The freedom to distribute copies of your modified versions to others