FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sql.js/examples/persistent.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
/
persistent.html
Copy path
More file actions
More file actions
Latest commit
History
History
History
70 lines (60 loc) · 2 KB
Breadcrumbs
sql.js
/
examples
/
persistent.html
Copy path
File metadata and controls
70 lines (60 loc) · 2 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
<!doctype html
>
<
html
>
<
head
>
<
meta
charset
="
utf8
"
>
<
title
>
Persistent sqlite
</
title
>
<
script
src
="
../dist/sql-wasm.js
"
>
</
script
>
</
head
>
<
body
>
<
p
>
You have seen this page
<
span
id
="
views
"
>
0
</
span
>
times.
</
p
>
<
div
>
You have been here on the following dates:
<
ol
id
="
dates
"
>
</
ol
>
</
div
>
<
script
>
var
baseUrl
=
'../dist/'
;
function
toBinArray
(
str
)
{
var
l
=
str
.
length
,
arr
=
new
Uint8Array
(
l
)
;
for
(
var
i
=
0
;
i
<
l
;
i
++
)
arr
[
i
]
=
str
.
charCodeAt
(
i
)
;
return
arr
;
}
function
toBinString
(
arr
)
{
var
uarr
=
new
Uint8Array
(
arr
)
;
var
strings
=
[
]
,
chunksize
=
0xffff
;
// There is a maximum stack size. We cannot call String.fromCharCode with as many arguments as we want
for
(
var
i
=
0
;
i
*
chunksize
<
uarr
.
length
;
i
++
)
{
strings
.
push
(
String
.
fromCharCode
.
apply
(
null
,
uarr
.
subarray
(
i
*
chunksize
,
(
i
+
1
)
*
chunksize
)
)
)
;
}
return
strings
.
join
(
''
)
;
}
// Normally Sql.js tries to load sql-wasm.wasm relative to the page, not relative to the javascript
// doing the loading. So, we help it find the .wasm file with this function.
var
config
=
{
locateFile
:
filename
=>
`
${
baseUrl
}
/
${
filename
}
`
}
initSqlJs
(
config
)
.
then
(
function
(
SQL
)
{
var
dbstr
=
window
.
localStorage
.
getItem
(
"viewcount.sqlite"
)
;
if
(
dbstr
)
{
var
db
=
new
SQL
.
Database
(
toBinArray
(
dbstr
)
)
;
}
else
{
var
db
=
new
SQL
.
Database
(
)
;
db
.
run
(
"CREATE TABLE views (date INTEGER PRIMARY KEY)"
)
;
}
db
.
run
(
"INSERT INTO views(date) VALUES (?)"
,
[
Date
.
now
(
)
]
)
;
document
.
getElementById
(
'views'
)
.
textContent
=
db
.
exec
(
"SELECT COUNT(*) FROM views"
)
[
0
]
.
values
[
0
]
[
0
]
;
var
count
=
0
,
dates
=
document
.
getElementById
(
"dates"
)
;
db
.
each
(
"SELECT date FROM views ORDER BY date ASC"
,
function
callback
(
row
)
{
var
li
=
document
.
createElement
(
"li"
)
;
li
.
textContent
=
new
Date
(
row
.
date
)
;
dates
.
appendChild
(
li
)
;
}
,
function
done
(
)
{
var
dbstr
=
toBinString
(
db
.
export
(
)
)
;
window
.
localStorage
.
setItem
(
"viewcount.sqlite"
,
dbstr
)
;
}
)
;
}
)
;
</
script
>
</
body
>
</
html
>
Back
|
FazBrowse Home
|
New Git URL