Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
lucas.parsy
jio
Commits
cf923fa7
Commit
cf923fa7
authored
Dec 02, 2015
by
lucas.parsy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
corrected bugs in websqlstorage breaking rsvp queues.
added sinon spy tests in websqlstorage test file.
parent
b864cc1c
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
698 additions
and
43 deletions
+698
-43
src/jio.storage/websqlstorage.js
src/jio.storage/websqlstorage.js
+48
-13
test/jio.storage/websqlstorage.tests.js
test/jio.storage/websqlstorage.tests.js
+650
-30
No files found.
src/jio.storage/websqlstorage.js
View file @
cf923fa7
...
...
@@ -37,7 +37,10 @@
});
}
function
createDatabase
(
db
)
{
function
initDatabase
(
that
)
{
var
db
=
that
.
_database
;
if
(
that
.
_base_created
===
true
)
{
return
;
}
that
.
_base_created
=
true
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
sqlExec
(
db
,
"
CREATE TABLE IF NOT EXISTS documents
"
+
...
...
@@ -89,7 +92,7 @@
throw
new
TypeError
(
"
blob_len parameter must be a number >= 20
"
);
}
this
.
_blob_length
=
spec
.
blob_length
||
2000000
;
createDatabase
(
this
.
_database
)
;
this
.
_base_created
=
false
;
}
function
addProperty
(
db
,
id
,
prop
,
value
)
{
...
...
@@ -109,11 +112,15 @@
websqlStorage
.
prototype
.
put
=
function
(
id
,
param
)
{
var
db
=
this
.
_database
,
that
=
this
,
dataString
=
JSON
.
stringify
(
param
),
i
,
arrayLen
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
initDatabase
(
that
);
})
.
push
(
function
()
{
return
sqlExec
(
db
,
"
INSERT OR REPLACE INTO
"
+
"
documents(id, data) VALUES(?,?)
"
,
...
...
@@ -139,9 +146,13 @@
};
websqlStorage
.
prototype
.
remove
=
function
(
id
)
{
var
db
=
this
.
_database
;
var
db
=
this
.
_database
,
that
=
this
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
initDatabase
(
that
);
})
.
push
(
function
()
{
return
sqlExec
(
db
,
"
DELETE FROM documents WHERE id = ?
"
,
[
id
]);
})
...
...
@@ -155,9 +166,13 @@
};
websqlStorage
.
prototype
.
get
=
function
(
id
)
{
var
db
=
this
.
_database
;
var
db
=
this
.
_database
,
that
=
this
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
initDatabase
(
that
);
})
.
push
(
function
()
{
return
sqlExec
(
db
,
"
SELECT data FROM documents WHERE id = ?
"
,
[
id
]);
})
...
...
@@ -170,9 +185,13 @@
};
websqlStorage
.
prototype
.
allAttachments
=
function
(
id
)
{
var
db
=
this
.
_database
;
var
db
=
this
.
_database
,
that
=
this
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
initDatabase
(
that
);
})
.
push
(
function
()
{
return
sqlExec
(
db
,
"
SELECT COUNT(*) FROM documents WHERE id = ?
"
,
[
id
]);
})
...
...
@@ -195,11 +214,10 @@
});
};
function
sendBlobPart
(
db
,
id
,
name
,
blob
,
nbSlice
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
readBlobAsDataURL
(
blob
);
})
function
sendBlobPart
(
db
,
id
,
name
,
blob
,
nbSlice
,
queue
)
{
queue
.
push
(
function
()
{
return
jIO
.
util
.
readBlobAsDataURL
(
blob
);
})
.
push
(
function
(
strBlob
)
{
strBlob
=
strBlob
.
currentTarget
.
result
;
return
sqlExec
(
db
,
"
INSERT INTO blob(id, attachment, part, blob)
"
+
...
...
@@ -209,9 +227,13 @@
websqlStorage
.
prototype
.
putAttachment
=
function
(
id
,
name
,
blob
)
{
var
db
=
this
.
_database
,
that
=
this
,
partSize
=
this
.
_blob_length
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
initDatabase
(
that
);
})
.
push
(
function
()
{
return
sqlExec
(
db
,
"
SELECT COUNT(*) FROM documents WHERE id = ?
"
,
[
id
]);
})
...
...
@@ -233,17 +255,20 @@
})
.
push
(
function
()
{
var
blobSize
=
blob
.
size
,
queue
=
new
RSVP
.
Queue
(),
i
,
index
;
for
(
i
=
0
,
index
=
0
;
i
<
blobSize
;
i
+=
partSize
,
index
+=
1
)
{
sendBlobPart
(
db
,
id
,
name
,
blob
.
slice
(
i
,
i
+
partSize
),
index
);
sendBlobPart
(
db
,
id
,
name
,
blob
.
slice
(
i
,
i
+
partSize
),
index
,
queue
);
}
return
queue
;
});
};
websqlStorage
.
prototype
.
getAttachment
=
function
(
id
,
name
,
options
)
{
var
db
=
this
.
_database
,
that
=
this
,
partSize
=
this
.
_blob_length
,
start
,
end
,
...
...
@@ -271,6 +296,9 @@
}
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
initDatabase
(
that
);
})
.
push
(
function
()
{
var
command
=
"
SELECT part, blob FROM blob WHERE id = ? AND
"
+
"
attachment = ? AND part >= ?
"
,
...
...
@@ -312,9 +340,12 @@
};
websqlStorage
.
prototype
.
removeAttachment
=
function
(
id
,
name
)
{
var
db
=
this
.
_database
;
var
db
=
this
.
_database
,
that
=
this
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
initDatabase
(
that
);
})
.
push
(
function
()
{
return
sqlExec
(
db
,
"
DELETE FROM attachment WHERE
"
+
"
id = ? AND attachment = ?
"
,
[
id
,
name
]);
...
...
@@ -333,6 +364,7 @@
websqlStorage
.
prototype
.
buildQuery
=
function
(
options
)
{
var
db
=
this
.
_database
,
that
=
this
,
query
=
"
SELECT id
"
;
if
(
options
===
undefined
)
{
options
=
{};
}
...
...
@@ -342,6 +374,9 @@
query
+=
"
FROM documents ORDER BY id
"
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
initDatabase
(
that
);
})
.
push
(
function
()
{
return
sqlExec
(
db
,
query
,
[]);
})
...
...
test/jio.storage/websqlstorage.tests.js
View file @
cf923fa7
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment