1

suppose we have a table of fruits and we want to insert multiple record in one query using TypeORM

apple = {
    color: "Green",
    name:  "apple",
    price: 400
}
banana = {
    color: "yellow",
    name:  "banana",
    price: 700
}
fruits = [apple, banana]
repo = repository(fruit_repo)
repo.insert(fruits)

The last line does not work for list how do i insert in one query without a for loop

1 Answer 1

1

It really depends in the modeling of the entities.

Let's say you have an entity holding a relation to another Fruit entity in a many form, you can use cascade: true, and then TypeORM will save the array in a single line, also creating the fruit entities.

Please view TypeORM docs for further information.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.