-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.js
More file actions
111 lines (100 loc) · 4.55 KB
/
sql.js
File metadata and controls
111 lines (100 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
///<reference path='node.d.ts'/>
var aps;
(function (aps) {
var edge = require('edge');
var conStr = '';
/**
* Must be called first.
* Sets the connection string to be used by all other calls to the aps-sql library.
*
* @param {string} str The connection string to use.
*/
function connectionString(str) {
conStr = str;
}
aps.connectionString = connectionString;
/**
* Executes a query and returns the result. Must have called 'connectionString()' first.
*
* *Important Note: converts all results from the database into JS. Don't just return everything otherwise you may run out of memory.
*
* @param {string} command The SQL command string to run
* @param {object} params An optional object containing a list of @ parameters & values that are used in the previous command string.
* @returns An array of arrays. First element contains the header row, all remaining arrays contain the data for the row.
*/
function executeQuery(command, params) {
return functions({ fn: 'executeSync', conStr: conStr, command: command, params: params }, true).Result;
}
aps.executeQuery = executeQuery;
/**
* Executes a query that does not have a result. Must have called 'connectionString()' first.
*
* @param {string} command The SQL command string to run
* @param {object} params An optional object containing a list of @ parameters & values that are used in the previous command string.
*/
function executeNonQuery(command, params) {
functions({ fn: 'nonQuerySync', conStr: conStr, command: command, params: params }, true);
}
aps.executeNonQuery = executeNonQuery;
/**
* Begins a new transaction. Must have called 'connectionString()' first.
*
* @returns A Transaction object which can be used to execute queries, and commit or cancel the transaction.
*/
function beginTransaction() {
var transCode = functions({ fn: 'beginTransaction', conStr: conStr }, true);
return new Transaction(transCode);
}
aps.beginTransaction = beginTransaction;
var Transaction = (function () {
function Transaction(transaction) {
this.transaction = transaction;
}
/**
* Executes a query and returns the result.
*
* *Important Note: converts all results from the database into JS. Don't just return everything otherwise you may run out of memory.
*
* @param {string} command The SQL command string to run
* @param {object} params An optional object containing a list of @ parameters & values that are used in the previous command string.
* @returns An array of arrays. First element contains the header row, all remaining arrays contain the data for the row.
*/
Transaction.prototype.executeQuery = function (command, params) {
return functions({ fn: 'transactionExecuteSync', transaction: this.transaction, conStr: conStr, command: command, params: params }, true).Result;
};
/**
* Executes a query that does not have a result.
*
* @param {string} command The SQL command string to run
* @param {object} params An optional object containing a list of @ parameters & values that are used in the previous command string.
*/
Transaction.prototype.executeNonQuery = function (command, params) {
return functions({ fn: 'transactionNonQuerySync', transaction: this.transaction, conStr: conStr, command: command, params: params }, true).Result;
};
/**
* Commits the transaction and closes the database connection.
*/
Transaction.prototype.commit = function () {
return functions({ fn: 'commitTransaction', transaction: this.transaction }, true);
};
/**
* Rolls back the transaction and closes the database connection.
*/
Transaction.prototype.cancel = function () {
return functions({ fn: 'cancelTransaction', transaction: this.transaction }, true);
};
return Transaction;
})();
aps.Transaction = Transaction;
//#region Edge Function Inits
var functions = edge.func({
source: __dirname + "/.cs/Sql.cs",
typeName: 'aps_sql_cs.Sql',
methodName: 'Invoke',
references: ['System.dll', 'System.Data.dll']
});
})(aps || (aps = {}));
exports.connectionString = aps.connectionString;
exports.executeQuery = aps.executeQuery;
exports.executeNonQuery = aps.executeNonQuery;
exports.beginTransaction = aps.beginTransaction;