FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript/tutorials/threejs/idb.js at main · iu5git/JavaScript · GitHub
iu5git
/
JavaScript
Public
Notifications
You must be signed in to change notification settings
Fork
21
Star
52
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript
/
tutorials
/
threejs
/
idb.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
44 lines (41 loc) · 1.48 KB
Breadcrumbs
JavaScript
/
tutorials
/
threejs
/
idb.js
Copy path
File metadata and controls
44 lines (41 loc) · 1.48 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
// Простая обёртка для работы с IndexedDB
function
openDB
(
)
{
return
new
Promise
(
(
resolve
,
reject
)
=>
{
const
request
=
indexedDB
.
open
(
"ModelGalleryDB"
,
1
)
;
request
.
onupgradeneeded
=
(
event
)
=>
{
const
db
=
event
.
target
.
result
;
if
(
!
db
.
objectStoreNames
.
contains
(
'models'
)
)
{
db
.
createObjectStore
(
'models'
,
{
keyPath
:
'id'
,
autoIncrement
:
true
}
)
;
}
}
;
request
.
onsuccess
=
(
)
=>
resolve
(
request
.
result
)
;
request
.
onerror
=
(
)
=>
reject
(
request
.
error
)
;
}
)
;
}
function
addModelToDB
(
model
)
{
return
openDB
(
)
.
then
(
db
=>
new
Promise
(
(
resolve
,
reject
)
=>
{
const
tx
=
db
.
transaction
(
'models'
,
'readwrite'
)
;
const
store
=
tx
.
objectStore
(
'models'
)
;
const
req
=
store
.
add
(
model
)
;
req
.
onsuccess
=
(
)
=>
resolve
(
req
.
result
)
;
req
.
onerror
=
(
)
=>
reject
(
req
.
error
)
;
}
)
)
;
}
function
getAllModelsFromDB
(
)
{
return
openDB
(
)
.
then
(
db
=>
new
Promise
(
(
resolve
,
reject
)
=>
{
const
tx
=
db
.
transaction
(
'models'
,
'readonly'
)
;
const
store
=
tx
.
objectStore
(
'models'
)
;
const
req
=
store
.
getAll
(
)
;
req
.
onsuccess
=
(
)
=>
resolve
(
req
.
result
)
;
req
.
onerror
=
(
)
=>
reject
(
req
.
error
)
;
}
)
)
;
}
function
getModelByIdFromDB
(
id
)
{
return
openDB
(
)
.
then
(
db
=>
new
Promise
(
(
resolve
,
reject
)
=>
{
const
tx
=
db
.
transaction
(
'models'
,
'readonly'
)
;
const
store
=
tx
.
objectStore
(
'models'
)
;
const
req
=
store
.
get
(
Number
(
id
)
)
;
req
.
onsuccess
=
(
)
=>
resolve
(
req
.
result
)
;
req
.
onerror
=
(
)
=>
reject
(
req
.
error
)
;
}
)
)
;
}
Back
|
FazBrowse Home
|
New Git URL