我如何使用knex.js调用具有表值参数的存储过程

问题描述

如何使用knex.js调用具有表值参数的存储过程?我在documentation中找不到任何提及如何进行的内容

/* Create a table type. */
CREATE TYPE TestType AS TABLE (
 Name VARCHAR(50),Age INT);
GO
/* Create a stored procedure. */
CREATE PROCEDURE MyCustomStoredProcedure (@tvp TestType readonly) AS SELECT * FROM @tvp

我发现了使用表值参数的node-mssql的示例。如果您对如何使用knex.js有所了解,将不胜感激。

// node-mssql

const tvp = new sql.Table() // You can optionally specify table type name in the first argument.

// Columns must correspond with type we have created in database.
tvp.columns.add('Name',sql.VarChar(50))
tvp.columns.add('Age',sql.Int)

// Add rows
tvp.rows.add('Mark',21) // Values are in same order as columns.

const request = new sql.Request()
request.input('tvp',tvp)
request.execute('MyCustomStoredProcedure',(err,result) => {
    console.dir(result.recordsets[0][0]) // {Name: 'Mark',Age: 21}
})

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)