本文整理汇总了TypeScript中mssql.DateTime2函数的典型用法代码示例。如果您正苦于以下问题:TypeScript DateTime2函数的具体用法?TypeScript DateTime2怎么用?TypeScript DateTime2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DateTime2函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
var connection: sql.ConnectionPool = new sql.ConnectionPool(config, function (err: any) {
if (err != null) {
console.warn("Issue with connecting to SQL Server!");
}
else {
connection.query`SELECT ${1} as value`.then(res => { });
var requestQuery = new sql.Request(connection);
var getArticlesQuery = "SELECT * FROM TABLE";
requestQuery.query(getArticlesQuery, function (err, result) {
if (err) {
console.error(`Error happened calling Query: ${err.name} ${err.message}`);
}
// checking to see if the articles returned as at least one.
else if (result.recordset.length > 0) {
}
});
getArticlesQuery = "SELECT 1 as value FROM TABLE";
requestQuery.query<Entity>(getArticlesQuery, function (err, result) {
if (err) {
console.error(`Error happened calling Query: ${err.name} ${err.message}`);
}
// checking to see if the articles returned as at least one.
else if (result.recordset.length > 0 && result.recordset[0].value) {
}
});
var requestStoredProcedure = new sql.Request(connection);
var testId: number = 0;
var testString: string = 'test';
requestStoredProcedure.input('pId', testId);
requestStoredProcedure.input('pString', testString);
requestStoredProcedure.execute('StoredProcedureName', function (err, recordsets, returnValue) {
if (err != null) {
console.error(`Error happened calling Query: ${err.name} ${err.message}`);
}
else {
console.info(returnValue);
}
});
requestStoredProcedure.execute<Entity>('StoredProcedureName', function (err, recordsets, returnValue) {
if (err != null) {
console.error(`Error happened calling Query: ${err.name} ${err.message}`);
}
else {
console.info(returnValue);
}
});
var requestStoredProcedureWithOutput = new sql.Request(connection);
var testId: number = 0;
var testString: string = 'test';
requestStoredProcedureWithOutput.input("name", sql.VarChar, "abc"); // varchar(3)
requestStoredProcedureWithOutput.input("name", sql.VarChar(50), "abc"); // varchar(MAX)
requestStoredProcedureWithOutput.output("name", sql.VarChar); // varchar(8000)
requestStoredProcedureWithOutput.output("name", sql.VarChar, "abc"); // varchar(3)
requestStoredProcedureWithOutput.input("name", sql.Decimal, 155.33); // decimal(18, 0)
requestStoredProcedureWithOutput.input("name", sql.Decimal(10), 155.33); // decimal(10, 0)
requestStoredProcedureWithOutput.input("name", sql.Decimal(10, 2), 155.33); // decimal(10, 2)
requestStoredProcedureWithOutput.input("name", sql.DateTime2, new Date()); // datetime2(7)
requestStoredProcedureWithOutput.input("name", sql.DateTime2(5), new Date()); // datetime2(5)
requestStoredProcedure.execute('StoredProcedureName', function (err, recordsets, returnValue) {
if (err != null) {
console.error(`Error happened calling Query: ${err.name} ${err.message}`);
}
else {
console.info(requestStoredProcedureWithOutput.parameters['output'].value);
}
});
requestStoredProcedure.execute<Entity>('StoredProcedureName', function (err, recordsets, returnValue) {
if (err != null) {
console.error(`Error happened calling Query: ${err.name} ${err.message}`);
}
else {
console.info(requestStoredProcedureWithOutput.parameters['output'].value);
}
});
}
});
示例2: varchar
/** Samples from https://github.com/patriksimek/node-mssql#data-types */
import * as sql from "mssql";
const request = new sql.Request();
request.input("name", sql.VarChar, "abc"); // varchar(3)
request.input("name", sql.VarChar(50), "abc"); // varchar(50)
request.input("name", sql.VarChar(sql.MAX), "abc"); // varchar(MAX)
request.output("name", sql.VarChar); // varchar(8000)
request.output("name", sql.VarChar, "abc"); // varchar(3)
request.input("name", sql.Decimal, 155.33); // decimal(18, 0)
request.input("name", sql.Decimal(10), 155.33); // decimal(10, 0)
request.input("name", sql.Decimal(10, 2), 155.33); // decimal(10, 2)
request.input("name", sql.DateTime2, new Date()); // datetime2(7)
request.input("name", sql.DateTime2(5), new Date()); // datetime2(5)