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
738c87bc
Commit
738c87bc
authored
Dec 09, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WebSQLStorage: naming convention
parent
23273a36
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
144 additions
and
151 deletions
+144
-151
src/jio.storage/websqlstorage.js
src/jio.storage/websqlstorage.js
+110
-105
test/jio.storage/websqlstorage.tests.js
test/jio.storage/websqlstorage.tests.js
+34
-46
No files found.
src/jio.storage/websqlstorage.js
View file @
738c87bc
...
...
@@ -17,62 +17,63 @@
/**
* The JIO Websql Storage extension
*
* @class
websql
Storage
* @class
WebSQL
Storage
* @constructor
*/
/*jslint unparam: true*/
function
sqlExec
(
db
,
transac
,
args
)
{
function
queueSql
(
db
,
query_list
,
argument_list
)
{
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
/*jslint unparam: true*/
db
.
transaction
(
function
(
tx
)
{
var
len
=
transac
.
length
,
res
=
[],
var
len
=
query_list
.
length
,
res
ult_list
=
[],
i
;
function
transacSuccess
(
tx
,
results
)
{
res
.
push
(
results
);
if
(
res
.
length
===
len
)
{
resolve
(
res
);
function
resolveTransaction
(
tx
,
result
)
{
res
ult_list
.
push
(
result
);
if
(
res
ult_list
.
length
===
len
)
{
resolve
(
res
ult_list
);
}
}
function
transacFailure
(
tx
,
error
)
{
function
rejectTransaction
(
tx
,
error
)
{
reject
(
error
);
return
true
;
}
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
tx
.
executeSql
(
transac
[
i
],
args
[
i
],
transacSuccess
,
transacFailure
);
tx
.
executeSql
(
query_list
[
i
],
argument_list
[
i
],
resolveTransaction
,
rejectTransaction
);
}
},
function
(
tx
,
error
)
{
reject
(
error
);
});
/*jslint unparam: false*/
});
}
/*jslint unparam: false*/
function
initDatabase
(
db
)
{
var
quer
ies
;
queries
=
[
"
CREATE TABLE IF NOT EXISTS documents
"
+
"
(id VARCHAR PRIMARY KEY NOT NULL, data TEXT)
"
,
"
CREATE TABLE IF NOT EXISTS attachment
"
+
"
(id VARCHAR, attachment VARCHAR,
"
+
"
CONSTRAINT un_id_attachment UNIQUE (id, attachment))
"
,
"
CREATE TABLE IF NOT EXISTS blob
"
+
"
(id VARCHAR, attachment VARCHAR, part INT, blob TEXT)
"
,
"
CREATE TRIGGER IF NOT EXISTS jIOremove
"
+
"
BEFORE DELETE ON documents FOR EACH ROW BEGIN DELETE
"
+
"
FROM attachment WHERE id = OLD.id;END;
"
,
"
CREATE TRIGGER IF NOT EXISTS jIOremoveAttachment
"
+
"
BEFORE DELETE ON attachment FOR EACH ROW
"
+
"
BEGIN DELETE from blob WHERE id = OLD.id
"
+
"
AND attachment = OLD.attachment;END;
"
];
var
quer
y_list
=
[
"
CREATE TABLE IF NOT EXISTS document
"
+
"
(id VARCHAR PRIMARY KEY NOT NULL, data TEXT)
"
,
"
CREATE TABLE IF NOT EXISTS attachment
"
+
"
(id VARCHAR, attachment VARCHAR,
"
+
"
CONSTRAINT uniq UNIQUE (id, attachment))
"
,
"
CREATE TABLE IF NOT EXISTS blob
"
+
"
(id VARCHAR, attachment VARCHAR, part INT, blob TEXT)
"
,
"
CREATE TRIGGER IF NOT EXISTS remove
"
+
"
BEFORE DELETE ON document FOR EACH ROW BEGIN DELETE
"
+
"
FROM attachment WHERE id = OLD.id;END;
"
,
"
CREATE TRIGGER IF NOT EXISTS removeAttachment
"
+
"
BEFORE DELETE ON attachment FOR EACH ROW
"
+
"
BEGIN DELETE from blob WHERE id = OLD.id
"
+
"
AND attachment = OLD.attachment;END;
"
];
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
sqlExec
(
db
,
queries
,
[[],
[],
[],
[],
[]]);
return
queueSql
(
db
,
query_list
,
[[],
[],
[],
[],
[]]);
});
}
function
websql
Storage
(
spec
)
{
function
WebSQL
Storage
(
spec
)
{
if
(
typeof
spec
.
database
!==
'
string
'
||
!
spec
.
database
)
{
throw
new
TypeError
(
"
database must be a string
"
+
"
which contains more than one character.
"
);
...
...
@@ -85,41 +86,41 @@
throw
new
TypeError
(
"
blob_len parameter must be a number >= 20
"
);
}
this
.
_blob_length
=
spec
.
blob_length
||
2000000
;
this
.
_init_
ba
se
=
initDatabase
(
this
.
_database
);
this
.
_init_
db_promi
se
=
initDatabase
(
this
.
_database
);
}
websql
Storage
.
prototype
.
put
=
function
(
id
,
param
)
{
WebSQL
Storage
.
prototype
.
put
=
function
(
id
,
param
)
{
var
db
=
this
.
_database
,
that
=
this
,
data
S
tring
=
JSON
.
stringify
(
param
);
data
_s
tring
=
JSON
.
stringify
(
param
);
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
that
.
_init_
ba
se
;
return
that
.
_init_
db_promi
se
;
})
.
push
(
function
()
{
return
sqlExec
(
db
,
[
"
INSERT OR REPLACE INTO
"
+
"
document
s
(id, data) VALUES(?,?)
"
],
[[
id
,
data
S
tring
]]);
return
queueSql
(
db
,
[
"
INSERT OR REPLACE INTO
"
+
"
document(id, data) VALUES(?,?)
"
],
[[
id
,
data
_s
tring
]]);
})
.
push
(
function
()
{
return
id
;
});
};
websql
Storage
.
prototype
.
remove
=
function
(
id
)
{
WebSQL
Storage
.
prototype
.
remove
=
function
(
id
)
{
var
db
=
this
.
_database
,
that
=
this
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
that
.
_init_
ba
se
;
return
that
.
_init_
db_promi
se
;
})
.
push
(
function
()
{
return
sqlExec
(
db
,
[
"
DELETE FROM documents
WHERE id = ?
"
],
[[
id
]]);
return
queueSql
(
db
,
[
"
DELETE FROM document
WHERE id = ?
"
],
[[
id
]]);
})
.
push
(
function
(
result
)
{
if
(
result
[
0
].
rowsAffected
===
0
)
{
.
push
(
function
(
result
_list
)
{
if
(
result
_list
[
0
].
rowsAffected
===
0
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
,
404
);
}
return
id
;
...
...
@@ -127,81 +128,82 @@
};
websql
Storage
.
prototype
.
get
=
function
(
id
)
{
WebSQL
Storage
.
prototype
.
get
=
function
(
id
)
{
var
db
=
this
.
_database
,
that
=
this
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
that
.
_init_
ba
se
;
return
that
.
_init_
db_promi
se
;
})
.
push
(
function
()
{
return
sqlExec
(
db
,
[
"
SELECT data FROM documents WHERE id = ?
"
],
[[
id
]]);
return
queueSql
(
db
,
[
"
SELECT data FROM document WHERE id = ?
"
],
[[
id
]]);
})
.
push
(
function
(
result
)
{
if
(
result
[
0
].
rows
.
length
===
0
)
{
.
push
(
function
(
result
_list
)
{
if
(
result
_list
[
0
].
rows
.
length
===
0
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
,
404
);
}
return
JSON
.
parse
(
result
[
0
].
rows
[
0
].
data
);
return
JSON
.
parse
(
result
_list
[
0
].
rows
[
0
].
data
);
});
};
websql
Storage
.
prototype
.
allAttachments
=
function
(
id
)
{
WebSQL
Storage
.
prototype
.
allAttachments
=
function
(
id
)
{
var
db
=
this
.
_database
,
that
=
this
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
that
.
_init_
ba
se
;
return
that
.
_init_
db_promi
se
;
})
.
push
(
function
()
{
return
sqlExec
(
db
,
[
"
SELECT id FROM documents WHERE id = ?
"
],
[[
id
]]);
return
queueSql
(
db
,
[
"
SELECT id FROM document WHERE id = ?
"
,
"
SELECT attachment FROM attachment WHERE id = ?
"
],
[[
id
],
[
id
]]);
})
.
push
(
function
(
result
)
{
if
(
result
[
0
].
rows
.
length
===
0
)
{
.
push
(
function
(
result
_list
)
{
if
(
result
_list
[
0
].
rows
.
length
===
0
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
,
404
);
}
return
sqlExec
(
db
,
[
"
SELECT attachment FROM attachment WHERE id = ?
"
],
[[
id
]]);
})
.
push
(
function
(
result
)
{
var
len
=
result
[
0
].
rows
.
length
,
var
len
=
result_list
[
1
].
rows
.
length
,
obj
=
{},
i
;
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
obj
[
result
[
0
].
rows
[
i
].
attachment
]
=
{};
obj
[
result
_list
[
1
].
rows
[
i
].
attachment
]
=
{};
}
return
obj
;
});
};
function
sendBlobPart
(
blob
,
arg
s
,
index
,
queue
)
{
function
sendBlobPart
(
blob
,
arg
ument_list
,
index
,
queue
)
{
queue
.
push
(
function
()
{
return
jIO
.
util
.
readBlobAsDataURL
(
blob
);
})
.
push
(
function
(
strBlob
)
{
arg
s
[
index
+
3
].
push
(
strBlob
.
currentTarget
.
result
);
arg
ument_list
[
index
+
3
].
push
(
strBlob
.
currentTarget
.
result
);
return
;
});
}
websql
Storage
.
prototype
.
putAttachment
=
function
(
id
,
name
,
blob
)
{
WebSQL
Storage
.
prototype
.
putAttachment
=
function
(
id
,
name
,
blob
)
{
var
db
=
this
.
_database
,
that
=
this
,
part
S
ize
=
this
.
_blob_length
;
part
_s
ize
=
this
.
_blob_length
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
that
.
_init_
ba
se
;
return
that
.
_init_
db_promi
se
;
})
.
push
(
function
()
{
return
sqlExec
(
db
,
[
"
SELECT id FROM documents
WHERE id = ?
"
],
[[
id
]]);
return
queueSql
(
db
,
[
"
SELECT id FROM document
WHERE id = ?
"
],
[[
id
]]);
})
.
push
(
function
(
result
)
{
var
quer
ies
=
[],
arg
s
=
[],
blob
S
ize
=
blob
.
size
,
var
quer
y_list
=
[],
arg
ument_list
=
[],
blob
_s
ize
=
blob
.
size
,
queue
=
new
RSVP
.
Queue
(),
i
,
index
;
...
...
@@ -209,32 +211,34 @@
if
(
result
[
0
].
rows
.
length
===
0
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot access subdocument
"
,
404
);
}
quer
ies
.
push
(
"
INSERT OR REPLACE INTO attachment(id, attachment)
"
+
quer
y_list
.
push
(
"
INSERT OR REPLACE INTO attachment(id, attachment)
"
+
"
VALUES(?, ?)
"
);
arg
s
.
push
([
id
,
name
]);
quer
ies
.
push
(
"
DELETE FROM blob WHERE id = ? AND attachment = ?
"
);
arg
s
.
push
([
id
,
name
]);
quer
ies
.
push
(
"
INSERT INTO blob(id, attachment, part, blob)
"
+
arg
ument_list
.
push
([
id
,
name
]);
quer
y_list
.
push
(
"
DELETE FROM blob WHERE id = ? AND attachment = ?
"
);
arg
ument_list
.
push
([
id
,
name
]);
quer
y_list
.
push
(
"
INSERT INTO blob(id, attachment, part, blob)
"
+
"
VALUES(?, ?, ?, ?)
"
);
args
.
push
([
id
,
name
,
-
1
,
blob
.
type
||
"
application/octet-stream
"
]);
argument_list
.
push
([
id
,
name
,
-
1
,
blob
.
type
||
"
application/octet-stream
"
]);
for
(
i
=
0
,
index
=
0
;
i
<
blob
Size
;
i
+=
partS
ize
,
index
+=
1
)
{
quer
ies
.
push
(
"
INSERT INTO blob(id, attachment, part, blob)
"
+
for
(
i
=
0
,
index
=
0
;
i
<
blob
_size
;
i
+=
part_s
ize
,
index
+=
1
)
{
quer
y_list
.
push
(
"
INSERT INTO blob(id, attachment, part, blob)
"
+
"
VALUES(?, ?, ?, ?)
"
);
args
.
push
([
id
,
name
,
index
]);
sendBlobPart
(
blob
.
slice
(
i
,
i
+
partSize
),
args
,
index
,
queue
);
argument_list
.
push
([
id
,
name
,
index
]);
sendBlobPart
(
blob
.
slice
(
i
,
i
+
part_size
),
argument_list
,
index
,
queue
);
}
queue
.
push
(
function
()
{
return
sqlExec
(
db
,
queries
,
args
);
return
queueSql
(
db
,
query_list
,
argument_list
);
});
return
queue
;
});
};
websql
Storage
.
prototype
.
getAttachment
=
function
(
id
,
name
,
options
)
{
WebSQL
Storage
.
prototype
.
getAttachment
=
function
(
id
,
name
,
options
)
{
var
db
=
this
.
_database
,
that
=
this
,
part
S
ize
=
this
.
_blob_length
,
part
_s
ize
=
this
.
_blob_length
,
start
,
end
,
start_index
,
...
...
@@ -253,35 +257,36 @@
400
);
}
start_index
=
Math
.
floor
(
start
/
part
S
ize
);
start_index
=
Math
.
floor
(
start
/
part
_s
ize
);
if
(
start
===
0
)
{
start_index
-=
1
;
}
end_index
=
Math
.
floor
(
end
/
part
S
ize
);
if
(
end
%
part
S
ize
===
0
)
{
end_index
=
Math
.
floor
(
end
/
part
_s
ize
);
if
(
end
%
part
_s
ize
===
0
)
{
end_index
-=
1
;
}
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
that
.
_init_
ba
se
;
return
that
.
_init_
db_promi
se
;
})
.
push
(
function
()
{
var
command
=
"
SELECT part, blob FROM blob WHERE id = ? AND
"
+
"
attachment = ? AND part >= ?
"
,
arg
s
=
[
id
,
name
,
start_index
];
arg
ument_list
=
[
id
,
name
,
start_index
];
if
(
end
!==
-
1
)
{
command
+=
"
AND part <= ?
"
;
arg
s
.
push
(
end_index
);
arg
ument_list
.
push
(
end_index
);
}
return
sqlExec
(
db
,
[
command
],
[
args
]);
return
queueSql
(
db
,
[
command
],
[
argument_list
]);
})
.
push
(
function
(
response
)
{
.
push
(
function
(
response
_list
)
{
var
i
,
blobArray
=
[],
response
,
blob_array
=
[],
blob
,
type
;
response
=
response
[
0
].
rows
;
response
=
response
_list
[
0
].
rows
;
if
(
response
.
length
===
0
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
,
404
);
}
...
...
@@ -290,30 +295,30 @@
type
=
response
[
i
].
blob
;
start_index
+=
1
;
}
else
{
blob
A
rray
.
push
(
jIO
.
util
.
dataURItoBlob
(
response
[
i
].
blob
));
blob
_a
rray
.
push
(
jIO
.
util
.
dataURItoBlob
(
response
[
i
].
blob
));
}
}
if
((
start
===
0
)
&&
(
options
.
end
===
undefined
))
{
return
new
Blob
(
blob
A
rray
,
{
type
:
type
});
return
new
Blob
(
blob
_a
rray
,
{
type
:
type
});
}
blob
=
new
Blob
(
blob
A
rray
,
{});
return
blob
.
slice
(
start
-
(
start_index
*
part
S
ize
),
blob
=
new
Blob
(
blob
_a
rray
,
{});
return
blob
.
slice
(
start
-
(
start_index
*
part
_s
ize
),
end
===
-
1
?
blob
.
size
:
end
-
(
start_index
*
part
S
ize
),
end
-
(
start_index
*
part
_s
ize
),
"
application/octet-stream
"
);
});
};
websql
Storage
.
prototype
.
removeAttachment
=
function
(
id
,
name
)
{
WebSQL
Storage
.
prototype
.
removeAttachment
=
function
(
id
,
name
)
{
var
db
=
this
.
_database
,
that
=
this
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
that
.
_init_
ba
se
;
return
that
.
_init_
db_promi
se
;
})
.
push
(
function
()
{
return
sqlExec
(
db
,
[
"
DELETE FROM attachment WHERE
"
+
return
queueSql
(
db
,
[
"
DELETE FROM attachment WHERE
"
+
"
id = ? AND attachment = ?
"
],
[[
id
,
name
]]);
})
.
push
(
function
(
result
)
{
...
...
@@ -324,26 +329,26 @@
});
};
websql
Storage
.
prototype
.
hasCapacity
=
function
(
name
)
{
WebSQL
Storage
.
prototype
.
hasCapacity
=
function
(
name
)
{
return
(
name
===
"
list
"
||
(
name
===
"
include
"
));
};
websql
Storage
.
prototype
.
buildQuery
=
function
(
options
)
{
WebSQL
Storage
.
prototype
.
buildQuery
=
function
(
options
)
{
var
db
=
this
.
_database
,
that
=
this
,
query
=
"
SELECT id
"
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
that
.
_init_
ba
se
;
return
that
.
_init_
db_promi
se
;
})
.
push
(
function
()
{
if
(
options
===
undefined
)
{
options
=
{};
}
if
(
options
.
include_docs
===
true
)
{
query
+=
"
, data AS doc
"
;
}
query
+=
"
FROM document
s
ORDER BY id
"
;
return
sqlExec
(
db
,
[
query
],
[[]]);
query
+=
"
FROM document ORDER BY id
"
;
return
queueSql
(
db
,
[
query
],
[[]]);
})
.
push
(
function
(
result
)
{
var
array
=
[],
...
...
@@ -361,6 +366,6 @@
});
};
jIO
.
addStorage
(
'
websql
'
,
websql
Storage
);
jIO
.
addStorage
(
'
websql
'
,
WebSQL
Storage
);
}(
jIO
,
RSVP
,
Blob
,
openDatabase
));
test/jio.storage/websqlstorage.tests.js
View file @
738c87bc
...
...
@@ -29,8 +29,8 @@
db
.
transaction
(
function
(
tx
)
{
/*jslint unparam: true*/
tx
.
executeSql
(
transac
,
args
,
function
(
tx
,
result
s
)
{
resolve
(
result
s
);
function
(
tx
,
result
)
{
resolve
(
result
);
},
function
(
tx
,
error
)
{
reject
(
error
);
...
...
@@ -41,34 +41,22 @@
}
function
spyStorageCreation
(
context
)
{
var
seven
=
false
;
if
(
context
.
spy
.
callCount
>=
5
)
{
seven
=
true
;
}
equal
(
seven
,
true
);
/* equal(context.spy.args[0][0],
'SELECT name FROM sqlite_master WHERE type ="table" ' +
'AND name != "__WebKitDatabaseInfoTable__"');
equal(context.spy.args[1][0], 'DELETE FROM documents');
equal(context.spy.args[2][0], 'DELETE FROM metadata');
equal(context.spy.args[3][0], 'DELETE FROM attachment');
equal(context.spy.args[4][0], 'DELETE FROM blob');
*/
ok
(
context
.
spy
.
callCount
>=
5
);
equal
(
context
.
spy
.
args
[
0
][
0
],
'
CREATE TABLE IF NOT EXISTS document
s
(id VARCHAR PRIMARY
'
+
'
CREATE TABLE IF NOT EXISTS document(id VARCHAR PRIMARY
'
+
'
KEY NOT NULL, data TEXT)
'
);
equal
(
context
.
spy
.
args
[
1
][
0
],
'
CREATE TABLE IF NOT EXISTS attachment(id VARCHAR, attachment
'
+
'
VARCHAR, CONSTRAINT un
_id_attachment
UNIQUE (id, attachment))
'
);
'
VARCHAR, CONSTRAINT un
iq
UNIQUE (id, attachment))
'
);
equal
(
context
.
spy
.
args
[
2
][
0
],
'
CREATE TABLE IF NOT EXISTS blob(id VARCHAR, attachment
'
+
'
VARCHAR, part INT, blob TEXT)
'
);
equal
(
context
.
spy
.
args
[
3
][
0
],
'
CREATE TRIGGER IF NOT EXISTS
jIO
remove BEFORE DELETE ON
'
+
'
document
s
FOR EACH ROW BEGIN DELETE FROM attachment
'
+
'
CREATE TRIGGER IF NOT EXISTS remove BEFORE DELETE ON
'
+
'
document FOR EACH ROW BEGIN DELETE FROM attachment
'
+
'
WHERE id = OLD.id;END;
'
);
equal
(
context
.
spy
.
args
[
4
][
0
],
'
CREATE TRIGGER IF NOT EXISTS
jIO
removeAttachment BEFORE DELETE ON
'
+
'
CREATE TRIGGER IF NOT EXISTS removeAttachment BEFORE DELETE ON
'
+
'
attachment FOR EACH ROW BEGIN DELETE from blob WHERE id = OLD.id
'
+
'
AND attachment = OLD.attachment;END;
'
);
}
...
...
@@ -159,7 +147,7 @@
}
});
test
(
"
can list document
s
"
,
function
()
{
test
(
"
can list document
"
,
function
()
{
var
context
=
this
;
stop
();
...
...
@@ -184,8 +172,6 @@
/////////////////////////////////////////////////////////////////
// websqlStorage.buildQuery
/////////////////////////////////////////////////////////////////
module
(
"
websqlStorage.buildQuery
"
,
{
setup
:
function
()
{
this
.
jio
=
jIO
.
createJIO
({
...
...
@@ -212,7 +198,7 @@
return
context
.
jio
.
allDocs
();
})
.
then
(
function
()
{
equal
(
context
.
spy
.
args
[
5
][
0
],
'
SELECT id FROM document
s
ORDER BY id
'
);
equal
(
context
.
spy
.
args
[
5
][
0
],
'
SELECT id FROM document ORDER BY id
'
);
deepEqual
(
context
.
spy
.
args
[
5
][
1
],
[]);
spyStorageCreation
(
context
);
return
;
...
...
@@ -242,7 +228,7 @@
})
.
then
(
function
()
{
equal
(
context
.
spy
.
args
[
5
][
0
],
'
SELECT id, data AS doc FROM document
s
ORDER BY id
'
);
'
SELECT id, data AS doc FROM document ORDER BY id
'
);
deepEqual
(
context
.
spy
.
args
[
5
][
1
],
[]);
spyStorageCreation
(
context
);
return
;
...
...
@@ -289,7 +275,7 @@
});
});
test
(
"
list all document
s
"
,
function
()
{
test
(
"
list all document
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
1
);
...
...
@@ -374,7 +360,9 @@
});
});
/////////////////////////////////////////////////////////////////
// websqlStorage.get
/////////////////////////////////////////////////////////////////
module
(
"
websqlStorage.get
"
,
{
setup
:
function
()
{
this
.
jio
=
jIO
.
createJIO
({
...
...
@@ -405,10 +393,10 @@
})
.
then
(
function
()
{
equal
(
context
.
spy
.
args
[
5
][
0
],
'
INSERT OR REPLACE INTO document
s
(id, data) VALUES(?,?)
'
);
'
INSERT OR REPLACE INTO document(id, data) VALUES(?,?)
'
);
deepEqual
(
context
.
spy
.
args
[
5
][
1
],
[
'
foo
'
,
'
{"title":"bar"}
'
]);
equal
(
context
.
spy
.
args
[
6
][
0
],
'
SELECT data FROM document
s
WHERE id = ?
'
);
'
SELECT data FROM document WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
6
][
1
],
[
'
foo
'
]);
spyStorageCreation
(
context
);
})
...
...
@@ -548,10 +536,10 @@
.
then
(
function
()
{
spyStorageCreation
(
context
);
equal
(
context
.
spy
.
args
[
5
][
0
],
'
INSERT OR REPLACE INTO document
s
(id, data) VALUES(?,?)
'
);
'
INSERT OR REPLACE INTO document(id, data) VALUES(?,?)
'
);
deepEqual
(
context
.
spy
.
args
[
5
][
1
],
[
'
foo
'
,
'
{"title":"bar"}
'
]);
equal
(
context
.
spy
.
args
[
6
][
0
],
'
SELECT id FROM document
s
WHERE id = ?
'
);
'
SELECT id FROM document WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
6
][
1
],
[
'
foo
'
]);
equal
(
context
.
spy
.
args
[
7
][
0
],
'
SELECT attachment FROM attachment WHERE id = ?
'
);
...
...
@@ -688,7 +676,7 @@
.
then
(
function
()
{
spyStorageCreation
(
context
);
equal
(
context
.
spy
.
args
[
5
][
0
],
'
INSERT OR REPLACE INTO document
s
(id, data) VALUES(?,?)
'
);
'
INSERT OR REPLACE INTO document(id, data) VALUES(?,?)
'
);
deepEqual
(
context
.
spy
.
args
[
5
][
1
],
[
'
foo
'
,
'
{"title":"bar"}
'
]);
})
.
then
(
function
()
{
...
...
@@ -761,9 +749,9 @@
.
then
(
function
()
{
spyStorageCreation
(
context
);
equal
(
context
.
spy
.
args
[
5
][
0
],
'
INSERT OR REPLACE INTO document
s
(id, data) VALUES(?,?)
'
);
'
INSERT OR REPLACE INTO document(id, data) VALUES(?,?)
'
);
deepEqual
(
context
.
spy
.
args
[
5
][
1
],
[
'
foo
'
,
'
{"title":"bar"}
'
]);
equal
(
context
.
spy
.
args
[
6
][
0
],
'
DELETE FROM document
s
WHERE id = ?
'
);
equal
(
context
.
spy
.
args
[
6
][
0
],
'
DELETE FROM document WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
6
][
1
],
[
'
foo
'
]);
})
.
then
(
function
()
{
...
...
@@ -801,10 +789,10 @@
.
then
(
function
()
{
spyStorageCreation
(
context
);
equal
(
context
.
spy
.
args
[
5
][
0
],
'
INSERT OR REPLACE INTO document
s
(id, data) VALUES(?,?)
'
);
'
INSERT OR REPLACE INTO document(id, data) VALUES(?,?)
'
);
deepEqual
(
context
.
spy
.
args
[
5
][
1
],
[
'
foo
'
,
'
{"title":"bar"}
'
]);
equal
(
context
.
spy
.
args
[
6
][
0
],
'
SELECT id FROM document
s
WHERE id = ?
'
);
'
SELECT id FROM document WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
6
][
1
],
[
'
foo
'
]);
equal
(
context
.
spy
.
args
[
7
][
0
],
'
INSERT OR REPLACE INTO attachment(id, attachment) VALUES(?, ?)
'
);
...
...
@@ -823,7 +811,7 @@
deepEqual
(
context
.
spy
.
args
[
10
][
1
],
[
'
foo
'
,
'
attachment1
'
,
0
,
'
data:;base64,YmFy
'
]);
equal
(
context
.
spy
.
args
[
11
][
0
],
'
SELECT id FROM document
s
WHERE id = ?
'
);
'
SELECT id FROM document WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
11
][
1
],
[
'
foo
'
]);
equal
(
context
.
spy
.
args
[
12
][
0
],
'
INSERT OR REPLACE INTO attachment(id, attachment) VALUES(?, ?)
'
);
...
...
@@ -840,7 +828,7 @@
'
INSERT INTO blob(id, attachment, part, blob)VALUES(?, ?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
15
][
1
],
[
'
foo
'
,
'
attachment2
'
,
0
,
'
data:;base64,YmFyMg==
'
]);
equal
(
context
.
spy
.
args
[
16
][
0
],
'
DELETE FROM document
s
WHERE id = ?
'
);
equal
(
context
.
spy
.
args
[
16
][
0
],
'
DELETE FROM document WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
16
][
1
],
[
'
foo
'
]);
})
.
then
(
function
()
{
...
...
@@ -870,7 +858,7 @@
return
context
.
jio
.
put
(
"
foo
"
,
{});
})
.
then
(
function
()
{
return
exec
(
"
SELECT id FROM document
s
"
,
[]);
return
exec
(
"
SELECT id FROM document
"
,
[]);
})
.
then
(
function
(
selectResult
)
{
equal
(
selectResult
.
rows
.
length
,
1
,
"
putAttachment done
"
);
...
...
@@ -880,7 +868,7 @@
})
.
then
(
function
(
result
)
{
equal
(
result
,
"
foo
"
);
return
exec
(
"
SELECT id FROM document
s
"
,
[]);
return
exec
(
"
SELECT id FROM document
"
,
[]);
})
.
then
(
function
(
selectResult
)
{
equal
(
selectResult
.
rows
.
length
,
0
,
"
remove done
"
);
...
...
@@ -931,11 +919,11 @@
.
then
(
function
()
{
spyStorageCreation
(
context
);
equal
(
context
.
spy
.
args
[
5
][
0
],
'
INSERT OR REPLACE INTO document
s
(id, data) VALUES(?,?)
'
);
'
INSERT OR REPLACE INTO document(id, data) VALUES(?,?)
'
);
deepEqual
(
context
.
spy
.
args
[
5
][
1
],
[
'
foo
'
,
'
{"title":"bar"}
'
]);
equal
(
context
.
spy
.
args
[
6
][
0
],
'
SELECT id FROM document
s
WHERE id = ?
'
);
'
SELECT id FROM document WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
6
][
1
],
[
'
foo
'
]);
equal
(
context
.
spy
.
args
[
7
][
0
],
'
INSERT OR REPLACE INTO attachment(id, attachment) VALUES(?, ?)
'
);
...
...
@@ -1087,11 +1075,11 @@
.
then
(
function
()
{
spyStorageCreation
(
context
);
equal
(
context
.
spy
.
args
[
5
][
0
],
'
INSERT OR REPLACE INTO document
s
(id, data) VALUES(?,?)
'
);
'
INSERT OR REPLACE INTO document(id, data) VALUES(?,?)
'
);
deepEqual
(
context
.
spy
.
args
[
5
][
1
],
[
'
foo
'
,
'
{"title":"bar"}
'
]);
equal
(
context
.
spy
.
args
[
6
][
0
],
'
SELECT id FROM document
s
WHERE id = ?
'
);
'
SELECT id FROM document WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
6
][
1
],
[
'
foo
'
]);
equal
(
context
.
spy
.
args
[
7
][
0
],
'
INSERT OR REPLACE INTO attachment(id, attachment) VALUES(?, ?)
'
);
...
...
@@ -1204,11 +1192,11 @@
.
then
(
function
()
{
spyStorageCreation
(
context
);
equal
(
context
.
spy
.
args
[
5
][
0
],
'
INSERT OR REPLACE INTO document
s
(id, data) VALUES(?,?)
'
);
'
INSERT OR REPLACE INTO document(id, data) VALUES(?,?)
'
);
deepEqual
(
context
.
spy
.
args
[
5
][
1
],
[
'
foo
'
,
'
{"title":"bar"}
'
]);
equal
(
context
.
spy
.
args
[
6
][
0
],
'
SELECT id FROM document
s
WHERE id = ?
'
);
'
SELECT id FROM document WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
6
][
1
],
[
'
foo
'
]);
equal
(
context
.
spy
.
args
[
7
][
0
],
'
INSERT OR REPLACE INTO attachment(id, attachment) VALUES(?, ?)
'
);
...
...
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