Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
18
Merge Requests
18
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
jio
Commits
06d0b3f4
Commit
06d0b3f4
authored
Jan 23, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
indexStorage: PUT new API and qunit
parent
f89b3df8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
125 additions
and
12 deletions
+125
-12
src/jio.storage/indexstorage.js
src/jio.storage/indexstorage.js
+11
-1
test/jiotests.js
test/jiotests.js
+114
-11
No files found.
src/jio.storage/indexstorage.js
View file @
06d0b3f4
...
...
@@ -214,6 +214,8 @@ jIO.addStorageType('indexed', function (spec, my) {
priv
.
index_suffix
,
option
,
function
(
response
)
{
console
.
log
(
"
index file found, we post(put)
"
);
console
.
log
(
indices
);
indices
=
response
;
f
.
postDocument
(
"
put
"
);
},
...
...
@@ -234,7 +236,7 @@ jIO.addStorageType('indexed', function (spec, my) {
f
.
postDocument
=
function
(
index_update_method
)
{
// if the index file already has an entry with this id,
// the document already exists
if
(
priv
.
docidInIndex
(
indices
,
doc
))
{
if
(
priv
.
docidInIndex
(
indices
,
doc
)
&&
index_update_method
===
'
POST
'
)
{
// POST the document already exists
that
.
error
({
"
status
"
:
409
,
...
...
@@ -292,6 +294,14 @@ jIO.addStorageType('indexed', function (spec, my) {
f
.
getIndices
();
};
/**
* Update the document metadata and update the index
* @method put
* @param {object} command The JIO command
*/
that
.
put
=
function
(
command
)
{
that
.
post
(
command
);
};
/*
/**
* @method formatToFileObject
...
...
test/jiotests.js
View file @
06d0b3f4
...
...
@@ -2628,13 +2628,10 @@ test ("Post", function () {
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
indexed
"
,
"
indices
"
:
[{
"
name
"
:
"
indexA
"
,
"
fields
"
:[
"
findMeA
"
]
},{
"
name
"
:
"
indexAB
"
,
"
fields
"
:[
"
findMeA
"
,
"
findMeB
"
]
}],
"
indices
"
:
[
{
"
name
"
:
"
indexA
"
,
"
fields
"
:[
"
findMeA
"
]},
{
"
name
"
:
"
indexAB
"
,
"
fields
"
:[
"
findMeA
"
,
"
findMeB
"
]}
],
"
sub_storage
"
:
{
"
type
"
:
"
local
"
,
"
username
"
:
"
ipost
"
,
...
...
@@ -2661,13 +2658,20 @@ test ("Post", function () {
"
indexA
"
:
{
"
keyword_abc
"
:[
"
some_id
"
]}
};
deepEqual
(
o
.
jio
.
get
(
"
ipost_indices.json
"
),
o
.
indexPost
,
"
Check index file
"
o
.
jio
.
get
(
"
ipost_indices.json
"
),
o
.
indexPost
,
"
Check index file
"
);
// post with escapable characters
o
.
doc
=
{
"
_id
"
:
"
other_id
"
,
"
title
"
:
"
myPost2
"
,
"
findMeA
"
:
"
keyword_*§$%&/()=?
"
,
"
findMeB
"
:
"
keyword_|ð@ł¶đæðſæðæſ³
"
};
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
other_id
"
},
"
Post with escapable characters
"
);
o
.
jio
.
post
(
o
.
doc
,
o
.
f
);
o
.
tick
(
o
);
// post and document already exists
o
.
doc
=
{
"
_id
"
:
"
some_id
"
,
"
title
"
:
"
myPost
2
"
,
o
.
doc
=
{
"
_id
"
:
"
some_id
"
,
"
title
"
:
"
myPost
3
"
,
"
findMeA
"
:
"
keyword_ghi
"
,
"
findMeB
"
:
"
keyword_jkl
"
}
o
.
spy
(
o
,
"
status
"
,
409
,
"
Post and document already exists
"
);
...
...
@@ -2676,6 +2680,105 @@ test ("Post", function () {
o
.
jio
.
stop
();
});
test
(
"
Put
"
,
function
(){
var
o
=
generateTools
(
this
);
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
indexed
"
,
"
indices
"
:
[
{
"
name
"
:
"
indexA
"
,
"
fields
"
:[
"
author
"
]},
{
"
name
"
:
"
indexAB
"
,
"
fields
"
:[
"
author
"
,
"
findMeC
"
]}
],
"
sub_storage
"
:
{
"
type
"
:
"
local
"
,
"
username
"
:
"
iput
"
,
"
application_name
"
:
"
iput
"
}
});
// put without id
// error 20 -> document id required
o
.
spy
(
o
,
"
status
"
,
20
,
"
Put without id
"
);
o
.
jio
.
put
({},
o
.
f
);
o
.
tick
(
o
);
// put non empty document
o
.
doc
=
{
"
_id
"
:
"
put1
"
,
"
title
"
:
"
myPut1
"
,
"
author
"
:
"
John Doe
"
};
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
put1
"
},
"
Put-create document
"
);
o
.
jio
.
put
(
o
.
doc
,
o
.
f
);
o
.
tick
(
o
);
// check index file
o
.
indexPut
=
{
"
indexA
"
:
{
"
John Doe
"
:
[
"
put1
"
]},
"
indexAB
"
:
{
"
John Doe
"
:
[
"
put1
"
]},
"
_id
"
:
"
iput_indices.json
"
};
deepEqual
(
o
.
jio
.
get
(
"
iput_indices.json
"
),
o
.
indexPut
,
"
Check index file
"
,
o
.
index
,
"
Check index file
"
);
// modify a document - modify keyword on index!
o
.
doc
=
{
"
_id
"
:
"
put1
"
,
"
title
"
:
"
myPuttter1
"
,
"
author
"
:
"
Jane Doe
"
};
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
put1
"
},
"
Modify document, update index file
"
);
o
.
jio
.
put
(
o
.
doc
,
o
.
f
);
o
.
tick
(
o
);
// check index file
o
.
index
=
{
"
indexA
"
:
{
"
Jane Doe
"
:
[
"
put1
"
]},
"
indexAB
"
:
{
"
Jane Doe
"
:
[
"
put1
"
]},
"
_id
"
:
"
iput_indices.json
"
};
deepEqual
(
o
.
jio
.
get
(
"
iput_indices.json
"
),
o
.
indexPut
,
"
Check index file
"
,
o
.
index
,
"
Check index file
"
);
// add new document with same keyword!
o
.
doc
=
{
"
_id
"
:
"
new_doc
"
,
"
title
"
:
"
myPut2
"
,
"
author
"
:
"
Jane Doe
"
};
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
new_doc
"
},
"
Add new document with same keyword
"
);
o
.
jio
.
put
(
o
.
doc
,
o
.
f
);
o
.
tick
(
o
);
// check index file
o
.
index
=
{
"
indexA
"
:
{
"
Jane Doe
"
:
[
"
put1
"
,
"
new_doc
"
]
},
"
indexAB
"
:
{
"
Jane Doe
"
:
[
"
put1
"
,
"
new_doc
"
]},
"
_id
"
:
"
iput_indices.json
"
};
deepEqual
(
o
.
jio
.
get
(
"
iput_indices.json
"
),
o
.
indexPut
,
"
Check index file
"
,
o
.
index
,
"
Check index file
"
);
// remove a keyword from an existing document
o
.
doc
=
{
"
_id
"
:
"
new_doc
"
,
"
title
"
:
"
myPut2
"
};
o
.
spy
(
o
,
"
value
"
,
{
"
ok
"
:
true
,
"
id
"
:
"
new_doc
"
},
"
Remove keyword from existing document
"
);
o
.
jio
.
put
(
o
.
doc
,
o
.
f
);
o
.
tick
(
o
);
// check index file
o
.
index
=
{
"
indexA
"
:
{
"
Jane Doe
"
:
[
"
put1
"
]
},
"
indexAB
"
:
{
"
Jane Doe
"
:
[
"
put1
"
]},
"
_id
"
:
"
iput_indices.json
"
};
deepEqual
(
o
.
jio
.
get
(
"
iput_indices.json
"
),
o
.
indexPut
,
"
Check index file
"
,
o
.
index
,
"
Check index file
"
);
o
.
jio
.
stop
();
});
/*
test ('Document load', function () {
var o = {}; o.clock = this.sandbox.useFakeTimers();
...
...
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