Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
¿Cómo devuelvo el valor modificado por un disparador DESPUÉS DE INSERTAR en Knex.js?

Quiero recuperar un valor después de insertar mis datos

 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"];

Sin embargo, la tabla en la que estoy insertando tiene un disparador AFTER INSERT que agregará un prefijo al campo sku_code :

 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

¿Hay alguna manera de obtener el valor después del disparador AFTER INSERT usando el return returning() de Knex? Sé que puedo agregar una lógica similar en mi código JS que anteponga manualmente el prefijo, pero no quiero duplicar la lógica.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!