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
Hide 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 @@
...
@@ -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
)
{
function
sendBlobPart
(
db
,
id
,
name
,
blob
,
nbSlice
)
{
return
new
RSVP
.
Queue
()
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
...
@@ -332,7 +323,41 @@
...
@@ -332,7 +323,41 @@
if
(
result
.
rowsAffected
===
0
)
{
if
(
result
.
rowsAffected
===
0
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
,
404
);
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 @@
...
@@ -14,7 +14,7 @@
db
=
openDatabase
(
'
jio:qunit
'
,
'
1.0
'
,
''
,
2
*
1024
*
1024
),
db
=
openDatabase
(
'
jio:qunit
'
,
'
1.0
'
,
''
,
2
*
1024
*
1024
),
j
;
j
;
function
exec
(
db
,
transac
,
args
)
{
function
exec
(
transac
,
args
)
{
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
db
.
transaction
(
function
(
tx
)
{
db
.
transaction
(
function
(
tx
)
{
/*jslint unparam: true*/
/*jslint unparam: true*/
...
@@ -33,16 +33,16 @@
...
@@ -33,16 +33,16 @@
function
deleteWebsql
()
{
function
deleteWebsql
()
{
return
new
RSVP
.
Queue
()
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
return
exec
(
db
,
"
DELETE FROM documents
"
,
[]);
return
exec
(
"
DELETE FROM documents
"
,
[]);
})
})
.
push
(
function
()
{
.
push
(
function
()
{
return
exec
(
db
,
"
DELETE FROM metadata
"
,
[]);
return
exec
(
"
DELETE FROM metadata
"
,
[]);
})
})
.
push
(
function
()
{
.
push
(
function
()
{
return
exec
(
db
,
"
DELETE FROM attachment
"
,
[]);
return
exec
(
"
DELETE FROM attachment
"
,
[]);
})
})
.
push
(
function
()
{
.
push
(
function
()
{
return
exec
(
db
,
"
DELETE FROM blob
"
,
[]);
return
exec
(
"
DELETE FROM blob
"
,
[]);
});
});
}
}
...
@@ -55,7 +55,7 @@
...
@@ -55,7 +55,7 @@
// websqlStorage.constructor
// websqlStorage.constructor
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
module
(
"
websqlStorage.constructor
"
);
module
(
"
websqlStorage.constructor
"
);
test
(
"
default unite valu
e
"
,
function
()
{
test
(
"
creation of the storag
e
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
websql
"
,
type
:
"
websql
"
,
database
:
"
qunit
"
database
:
"
qunit
"
...
@@ -64,6 +64,18 @@
...
@@ -64,6 +64,18 @@
equal
(
jio
.
__type
,
"
websql
"
);
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
// websqlStorage.buildQuery
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
...
@@ -86,7 +98,13 @@
...
@@ -86,7 +98,13 @@
return
context
.
jio
.
allDocs
();
return
context
.
jio
.
allDocs
();
})
})
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{});
deepEqual
(
result
,
{
"
data
"
:
{
"
rows
"
:
[
],
"
total_rows
"
:
0
}
});
})
})
.
fail
(
function
(
error
)
{
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
...
@@ -173,9 +191,7 @@
...
@@ -173,9 +191,7 @@
});
});
});
});
/////////////////////////////////////////////////////////////////
// websqlStorage.get
/////////////////////////////////////////////////////////////////
module
(
"
websqlStorage.get
"
,
{
module
(
"
websqlStorage.get
"
,
{
setup
:
function
()
{
setup
:
function
()
{
this
.
jio
=
jIO
.
createJIO
({
this
.
jio
=
jIO
.
createJIO
({
...
@@ -185,7 +201,6 @@
...
@@ -185,7 +201,6 @@
}
}
});
});
test
(
"
get inexistent document
"
,
function
()
{
test
(
"
get inexistent document
"
,
function
()
{
var
context
=
this
;
var
context
=
this
;
stop
();
stop
();
...
@@ -398,7 +413,39 @@
...
@@ -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
// websqlStorage.getAttachment
...
@@ -492,7 +539,7 @@
...
@@ -492,7 +539,7 @@
});
});
}
}
});
});
/*
test
(
"
remove attachment
"
,
function
()
{
test
(
"
remove attachment
"
,
function
()
{
var
context
=
this
,
var
context
=
this
,
attachment
=
"
attachment
"
;
attachment
=
"
attachment
"
;
...
@@ -507,14 +554,30 @@
...
@@ -507,14 +554,30 @@
return
context
.
jio
.
putAttachment
(
"
foo
"
,
attachment
,
big_string
);
return
context
.
jio
.
putAttachment
(
"
foo
"
,
attachment
,
big_string
);
})
})
.
then
(
function
()
{
.
then
(
function
()
{
exec("SELECT * FROM attachment ")
return
exec
(
"
SELECT id, attachment FROM attachment UNION ALL
"
+
return context.jio.getAttachment("foo", attachment,
"
SELECT id, attachment FROM blob
"
,
[]);
{"start": 15, "end": 25});
})
})
*/
.
then
(
function
(
selectResult
)
{
equal
(
selectResult
.
rows
.
length
,
2
,
"
putAttachment done
"
);
})
//bientot ici: de beaux tests.
.
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
// websqlStorage.putAttachment
...
@@ -528,5 +591,41 @@
...
@@ -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
));
}(
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