KyselyK
Kysely3y ago
Nil

how to insert an array of strings

hey guys,

I wanted to know how to store an array of strings with kysely, I created my table using migrations:

  await db.schema
    .withSchema("schemaName")
    .createTable("tableName")
    .addColumn("id", "bigserial", (col) => col.primaryKey())
    .addColumn("columnName", sql`text[]`)

I ran it this way and it created the table, but the problem now is inserting the data:

  const insertedProductId: any = await db
     .insertInto("teleclinica.product")
     .values({
       columnName: ["data1", "data2"]
     })
     .returning(['id'])
     .executeTakeFirstOrThrow()

I'm using postgresql, could you help me please
Was this page helpful?