FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
alasql/src/20database.js at develop · AlaSQL/alasql · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
AlaSQL
/
alasql
Public
Notifications
You must be signed in to change notification settings
Fork
694
Star
7.3k
Code
Issues
397
Pull requests
53
Discussions
Actions
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
alasql
/
src
/
20database.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
149 lines (123 loc) · 3.34 KB
Breadcrumbs
alasql
/
src
/
20database.js
Copy path
File metadata and controls
executable file
·
149 lines (123 loc) · 3.34 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
//
// Database class for Alasql.js
// Date: 03.11.2014
// (c) 2014, Andrey Gershun
//
*/
// Main Database class
/**
@class
Database
*/
var
Database
=
(
alasql
.
Database
=
function
(
databaseid
)
{
var
self
=
this
;
// self = function(a){console.log('OK',a);}
// self.prototype = this;
if
(
self
===
alasql
)
{
if
(
databaseid
)
{
// if(alasql.databases[databaseid]) {
self
=
alasql
.
databases
[
databaseid
]
;
// } else {
alasql
.
databases
[
databaseid
]
=
self
;
// }
if
(
!
self
)
{
throw
new
Error
(
`Database
${
databaseid
}
not found`
)
;
}
}
else
{
// Create new database (or get alasql?)
self
=
alasql
.
databases
.
alasql
;
// For SQL Server examples, USE tempdb
if
(
alasql
.
options
.
tsql
)
{
alasql
.
databases
.
tempdb
=
alasql
.
databases
.
alasql
;
}
// self = new Database(databaseid); // to call without new
}
}
if
(
!
databaseid
)
{
databaseid
=
'db'
+
alasql
.
databasenum
++
;
// Random name
}
// Step 1
self
.
databaseid
=
databaseid
;
alasql
.
databases
[
databaseid
]
=
self
;
self
.
dbversion
=
0
;
//Steps 2-5
self
.
tables
=
{
}
;
self
.
views
=
{
}
;
self
.
triggers
=
{
}
;
self
.
indices
=
{
}
;
// Step 6: Objects storage
self
.
objects
=
{
}
;
self
.
counter
=
0
;
self
.
resetSqlCache
(
)
;
return
self
;
}
)
;
/**
Reset SQL statements cache
*/
Database
.
prototype
.
resetSqlCache
=
function
(
)
{
this
.
sqlCache
=
{
}
;
// Cache for compiled SQL statements
this
.
sqlCacheSize
=
0
;
this
.
astCache
=
{
}
;
// Cache for AST objects
}
;
// Main SQL function
/**
Run SQL statement on database
@param
{
string
} sql SQL statement
@param
[object] params Parameters
@param
{
function
} cb callback
*/
Database
.
prototype
.
exec
=
function
(
sql
,
params
,
cb
)
{
return
alasql
.
dexec
(
this
.
databaseid
,
sql
,
params
,
cb
)
;
}
;
Database
.
prototype
.
autoval
=
function
(
tablename
,
colname
,
getNext
)
{
return
alasql
.
autoval
(
tablename
,
colname
,
getNext
,
this
.
databaseid
)
;
}
;
Database
.
prototype
.
transaction
=
function
(
cb
)
{
var
tx
=
new
alasql
.
Transaction
(
this
.
databaseid
)
;
var
res
=
cb
(
tx
)
;
return
res
;
}
;
/*/*
// // Compile
// var statement = this.compile(sql);
// // Run
// if(statement) {
// var data = statement(params, cb);
// return data;
// }
// return;
//
};
// // Async version of exec
// Database.prototype.aexec = function(sql, params) {
// var self = this;
// return new Promise(function(resolve, reject){
// alasql.dexec(this.databaseid,sql,params,resolve);
// });
//
};
*/
// Aliases like MS SQL
/*/*
Database.prototype.query = Database.prototype.exec;
Database.prototype.run = Database.prototype.exec;
Database.prototype.queryArray = function(sql, params, cb) {
return flatArray(this.exec(sql, params, cb));
}
Database.prototype.queryArrayOfArrays = function(sql, params, cb) {
return arrayOfArrays(this.exec(sql, params, cb));
}
Database.prototype.querySingle = function(sql, params, cb) {
return this.exec(sql, params, cb)[0];
}
Database.prototype.queryValue = function(sql, params, cb) {
var res = this.querySingle(sql, params, cb);
return res[Object.keys(res)[0]];
}
Database.prototype.value = Database.prototype.queryValue;
Database.prototype.row = Database.prototype.querySingle;
Database.prototype.array = Database.prototype.queryArray;
Database.prototype.matrix = Database.prototype.queryArrayOfArrays;
// Compile statements
Database.prototype.compile = function(sql, kind) {
return alasql.compile(sql, kind, databaseid);
};
*/
Back
|
FazBrowse Home
|
New Git URL