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
5e8b8a5a
Commit
5e8b8a5a
authored
Nov 30, 2015
by
lucas.parsy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added allDocs method in websqlStorage
added tests for Websqlstorage and refactored some tests.
parent
f5382029
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
155 additions
and
31 deletions
+155
-31
src/jio.storage/websqlstorage.js
src/jio.storage/websqlstorage.js
+35
-10
test/jio.storage/websqlstorage.tests.js
test/jio.storage/websqlstorage.tests.js
+120
-21
No files found.
src/jio.storage/websqlstorage.js
View file @
5e8b8a5a
...
...
@@ -195,15 +195,6 @@
});
};
websqlStorage
.
prototype
.
allDocs
=
function
()
{
var
db
=
this
.
_database
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
sqlExec
(
db
,
"
SELECT id FROM documents
"
);
});
};
function
sendBlobPart
(
db
,
id
,
name
,
blob
,
nbSlice
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
...
...
@@ -332,7 +323,41 @@
if
(
result
.
rowsAffected
===
0
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
,
404
);
}
return
id
;
return
name
;
});
};
websqlStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
return
(
name
===
"
list
"
||
(
name
===
"
include
"
));
};
websqlStorage
.
prototype
.
buildQuery
=
function
(
options
)
{
var
db
=
this
.
_database
,
query
=
"
SELECT id
"
;
if
(
options
===
undefined
)
{
options
=
{};
}
if
(
options
.
include_docs
===
true
)
{
query
+=
"
, data AS doc
"
;
}
query
+=
"
FROM documents ORDER BY id
"
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
sqlExec
(
db
,
query
,
[]);
})
.
push
(
function
(
result
)
{
var
array
=
[],
len
=
result
.
rows
.
length
,
i
;
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
array
.
push
(
result
.
rows
[
i
]);
array
[
i
].
value
=
{};
if
(
array
[
i
].
doc
!==
undefined
)
{
array
[
i
].
doc
=
JSON
.
parse
(
array
[
i
].
doc
);
}
}
return
array
;
});
};
...
...
test/jio.storage/websqlstorage.tests.js
View file @
5e8b8a5a
...
...
@@ -14,7 +14,7 @@
db
=
openDatabase
(
'
jio:qunit
'
,
'
1.0
'
,
''
,
2
*
1024
*
1024
),
j
;
function
exec
(
db
,
transac
,
args
)
{
function
exec
(
transac
,
args
)
{
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
db
.
transaction
(
function
(
tx
)
{
/*jslint unparam: true*/
...
...
@@ -33,16 +33,16 @@
function
deleteWebsql
()
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
exec
(
db
,
"
DELETE FROM documents
"
,
[]);
return
exec
(
"
DELETE FROM documents
"
,
[]);
})
.
push
(
function
()
{
return
exec
(
db
,
"
DELETE FROM metadata
"
,
[]);
return
exec
(
"
DELETE FROM metadata
"
,
[]);
})
.
push
(
function
()
{
return
exec
(
db
,
"
DELETE FROM attachment
"
,
[]);
return
exec
(
"
DELETE FROM attachment
"
,
[]);
})
.
push
(
function
()
{
return
exec
(
db
,
"
DELETE FROM blob
"
,
[]);
return
exec
(
"
DELETE FROM blob
"
,
[]);
});
}
...
...
@@ -55,7 +55,7 @@
// websqlStorage.constructor
/////////////////////////////////////////////////////////////////
module
(
"
websqlStorage.constructor
"
);
test
(
"
default unite valu
e
"
,
function
()
{
test
(
"
creation of the storag
e
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
type
:
"
websql
"
,
database
:
"
qunit
"
...
...
@@ -64,6 +64,18 @@
equal
(
jio
.
__type
,
"
websql
"
);
});
/////////////////////////////////////////////////////////////////
// websqlStorage.hasCapacity
/////////////////////////////////////////////////////////////////
module
(
"
websqlStorage.hasCapacity
"
);
test
(
"
can list documents
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
type
:
"
websql
"
,
database
:
"
qunit
"
});
ok
(
jio
.
hasCapacity
(
"
list
"
));
});
/////////////////////////////////////////////////////////////////
// websqlStorage.buildQuery
/////////////////////////////////////////////////////////////////
...
...
@@ -86,7 +98,13 @@
return
context
.
jio
.
allDocs
();
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{});
deepEqual
(
result
,
{
"
data
"
:
{
"
rows
"
:
[
],
"
total_rows
"
:
0
}
});
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -173,9 +191,7 @@
});
});
/////////////////////////////////////////////////////////////////
// websqlStorage.get
/////////////////////////////////////////////////////////////////
module
(
"
websqlStorage.get
"
,
{
setup
:
function
()
{
this
.
jio
=
jIO
.
createJIO
({
...
...
@@ -185,7 +201,6 @@
}
});
test
(
"
get inexistent document
"
,
function
()
{
var
context
=
this
;
stop
();
...
...
@@ -398,7 +413,39 @@
}
});
//bientot ici: de beaux tests.
test
(
"
remove document
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
3
);
deleteWebsql
()
.
then
(
function
()
{
return
context
.
jio
.
put
(
"
foo
"
,
{});
})
.
then
(
function
()
{
return
exec
(
"
SELECT id FROM documents
"
,
[]);
})
.
then
(
function
(
selectResult
)
{
equal
(
selectResult
.
rows
.
length
,
1
,
"
putAttachment done
"
);
})
.
then
(
function
()
{
return
context
.
jio
.
remove
(
"
foo
"
);
})
.
then
(
function
(
result
)
{
equal
(
result
,
"
foo
"
);
return
exec
(
"
SELECT id FROM documents
"
,
[]);
})
.
then
(
function
(
selectResult
)
{
equal
(
selectResult
.
rows
.
length
,
0
,
"
remove done
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// websqlStorage.getAttachment
...
...
@@ -492,7 +539,7 @@
});
}
});
/*
test
(
"
remove attachment
"
,
function
()
{
var
context
=
this
,
attachment
=
"
attachment
"
;
...
...
@@ -507,14 +554,30 @@
return
context
.
jio
.
putAttachment
(
"
foo
"
,
attachment
,
big_string
);
})
.
then
(
function
()
{
exec("SELECT * FROM attachment ")
return context.jio.getAttachment("foo", attachment,
{"start": 15, "end": 25});
return
exec
(
"
SELECT id, attachment FROM attachment UNION ALL
"
+
"
SELECT id, attachment FROM blob
"
,
[]);
})
*/
//bientot ici: de beaux tests.
.
then
(
function
(
selectResult
)
{
equal
(
selectResult
.
rows
.
length
,
2
,
"
putAttachment done
"
);
})
.
then
(
function
()
{
return
context
.
jio
.
removeAttachment
(
"
foo
"
,
attachment
);
})
.
then
(
function
(
result
)
{
equal
(
result
,
attachment
);
return
exec
(
"
SELECT id, attachment FROM attachment UNION ALL
"
+
"
SELECT id, attachment FROM blob
"
,
[]);
})
.
then
(
function
(
selectResult
)
{
equal
(
selectResult
.
rows
.
length
,
0
,
"
removeAttachment done
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// websqlStorage.putAttachment
...
...
@@ -528,5 +591,41 @@
}
});
//bientot ici: de beaux tests.
test
(
"
put attachment
"
,
function
()
{
var
context
=
this
,
attachment
=
"
attachment
"
;
stop
();
expect
(
2
);
deleteWebsql
()
.
then
(
function
()
{
return
context
.
jio
.
put
(
"
foo
"
,
{
"
title
"
:
"
bar
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
putAttachment
(
"
foo
"
,
attachment
,
big_string
);
})
.
then
(
function
()
{
return
exec
(
"
SELECT id, attachment FROM attachment UNION ALL
"
+
"
SELECT id, attachment FROM blob
"
,
[]);
})
.
then
(
function
(
selectResult
)
{
equal
(
selectResult
.
rows
.
length
,
2
,
"
putAttachment done
"
);
})
.
then
(
function
()
{
return
context
.
jio
.
getAttachment
(
"
foo
"
,
attachment
);
})
.
then
(
function
(
result
)
{
return
jIO
.
util
.
readBlobAsText
(
result
);
})
.
then
(
function
(
result
)
{
equal
(
result
.
target
.
result
,
big_string
,
"
attachment correctly fetched
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
}(
jIO
,
QUnit
,
openDatabase
,
Blob
));
\ No newline at end of file
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