Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
How do I return value modified by an AFTER INSERT trigger in Knex.js?

I want to get back a value after I insert my data

const data = {name: "Christmas Shirt 1", price: 5.99, sku: "20210911S", warehouse_id: 2}

const skuCode = await query.returning(['sku_code'], {includeTriggerModifications:true}).insert(data);

console.log(skuCode) // ["20210911-NY"];

However, the table that I'm inserting into has an AFTER INSERT trigger that will append a prefix to the sku_code field:

CREATE TRIGGER inventory_trigger
ON inventory AFTER TRIGGER AS
BEGIN
  UPDATE t
  SET sku_code = CASE t.warehouse_id
    WHEN 1 THEN t.sku_code + "NV"
    WHEN 2 THEN t.sku_code + "NY"
  END
  FROM inventory t
  JOIN inserted i ON t.id = i.id
END

Is there a way for me to get the value after the AFTER INSERT trigger using Knex's returning()? I know I can add similar logic in my JS code that manually prepends the prefix but I don't want to duplicate the logic.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda