I have a Typescript object like this (the properties are made up, but the object is in the form listed below):
shipments = [
{
id: 1,
name: 'test',
age: 2,
orderNumber: null
},
{
id: 2,
name: 'test2',
age: 4,
orderNumber: '1434'
},
]
I need to write a postgresql statement that takes that array and puts it into a table that has columns id, name, age, and orderNumber. I can't do any iteration on the data (that's why I'm trying to stuff an array I already have using one import statement - because it's way faster than iteration). I need to take that array - without adding any kind of Typescript manipulation to it - and use it in an postgresql insert statement. Is this possible? To maybe make more clear what I want to do, I want to take the shipments object from above and insert it similar to what this insert statement would do.
INSERT INTO table (id, name, age, orderNumber) VALUES (1, 'test', 2', null), (2, 'test2', 4, '1434')
But more automated such as:
INSERT INTO table (variable_column_list) VALUES shipments_array_with_only_values_not_keys
I saw an example using json_to_recordset, but it wasn't working for me, so the use case may have been different.
This is what I am currently doing, using adonis and multiInsert; however, that only allows 1000 records at a time. I was hoping for all the records in one postgres statement.
await Database.connection(tenant).table(table).multiInsert(shipments)
Thanks in advance, for the help!