Skip to main content

Insert

Use .insert to insert data into your table. This will return the number of records inserted.

const { db } = useEasybase();

await db('MOVIES').insert({ title: "Forrest Gump", rating: 82 }).one()
> 1

// { title: "Forrest Gump", rating: 82 }

Columns that are not passed in the new entry will be cast to null.

await db('MOVIES').insert({ title: "Forrest Gump" }).one()
> 1

// { title: "Forrest Gump", rating: null }

To insert multiple rows, pass multiple objects. Column names are inferred from the keys of all objects.

Executing this command with either .all or .one will only insert one copy of the provided rows.

await db('MOVIES').insert(
{ title: "Forrest Gump", rating: 82 },
{ title: "Joker", rating: 58 },
{ title: "Inception" }
).one()
> 3

// [
// { title: "Forrest Gump", rating: 82 },
// { title: "Joker", rating: 58 },
// { title: "Inception", rating: null }
// ]