FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sql.js/examples/requireJS.html at master · sql-js/sql.js · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
sql-js
/
sql.js
Public
Notifications
You must be signed in to change notification settings
Fork
1.1k
Star
13.7k
Code
Issues
127
Pull requests
15
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
sql.js
/
examples
/
requireJS.html
Copy path
More file actions
More file actions
Latest commit
History
History
History
60 lines (53 loc) · 1.94 KB
Breadcrumbs
sql.js
/
examples
/
requireJS.html
Copy path
File metadata and controls
60 lines (53 loc) · 1.94 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
<
meta
charset
="
utf8
"
/>
<
html
>
<
script
src
='
https://requirejs.org/docs/release/2.3.6/minified/require.js
'
>
</
script
>
<
script
>
var
baseUrl
=
'../dist'
require
.
config
(
{
baseUrl
:
baseUrl
}
)
;
// Options: 'sql-wasm', 'sql-asm', 'sql-asm-memory-growth.js', 'sql-wasm-debug', 'sql-asm-debug'
require
(
[
'sql-wasm'
]
,
function
success
(
initSqlJs
)
{
console
.
log
(
typeof
initSqlJs
)
;
if
(
typeof
initSqlJs
!==
'function'
)
{
document
.
body
.
style
.
backgroundColor
=
'red'
;
console
.
log
(
'initSqlJs returned: '
,
initSqlJs
)
;
alert
(
"Failed to require sql.js through AMD"
)
;
return
;
}
// The `initSqlJs` function is globally provided by all of the main dist files if loaded in the browser.
// We must specify this locateFile function if we are loading a wasm file from anywhere other than the current html page's folder.
var
config
=
{
locateFile
:
filename
=>
`
${
baseUrl
}
/
${
filename
}
`
}
initSqlJs
(
config
)
.
then
(
function
(
SQL
)
{
//Create the database
var
db
=
new
SQL
.
Database
(
)
;
// Run a query without reading the results
db
.
run
(
"CREATE TABLE test (col1, col2);"
)
;
// Insert two rows: (1,111) and (2,222)
db
.
run
(
"INSERT INTO test VALUES (?,?), (?,?)"
,
[
1
,
111
,
2
,
222
]
)
;
// Prepare a statement
var
stmt
=
db
.
prepare
(
"SELECT * FROM test WHERE col1 BETWEEN $start AND $end"
)
;
stmt
.
getAsObject
(
{
$start
:
1
,
$end
:
1
}
)
;
// {col1:1, col2:111}
// Bind new values
stmt
.
bind
(
{
$start
:
1
,
$end
:
2
}
)
;
while
(
stmt
.
step
(
)
)
{
//
var
row
=
stmt
.
getAsObject
(
)
;
// [...] do something with the row of result
console
.
log
(
'Here is a row: '
,
row
)
;
}
}
)
;
}
,
function
error
(
err
)
{
document
.
body
.
style
.
backgroundColor
=
'red'
;
console
.
log
(
err
)
;
alert
(
"Module load failed: "
+
err
)
;
}
)
;
</
script
>
<
body
>
Output is in Javscript console
</
body
>
</
html
>
Back
|
FazBrowse Home
|
New Git URL