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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Eugene Shen
jio
Commits
518eb3ba
Commit
518eb3ba
authored
Jul 03, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
splitstorage.js +1, allDocs WIP
parent
7ab7782a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
6 deletions
+93
-6
src/jio.storage/splitstorage.js
src/jio.storage/splitstorage.js
+93
-6
No files found.
src/jio.storage/splitstorage.js
View file @
518eb3ba
...
...
@@ -19,6 +19,8 @@
(
function
()
{
"
use strict
"
;
var
queries
;
/**
* Get the real type of an object
*
...
...
@@ -274,7 +276,7 @@
priv
.
send
(
'
get
'
,
doc
,
option
,
function
(
err
,
response
)
{
var
i
,
k
;
if
(
err
)
{
err
.
message
=
"
Unable to
pos
t document
"
;
err
.
message
=
"
Unable to
ge
t document
"
;
delete
err
.
index
;
return
that
.
error
(
err
);
}
...
...
@@ -297,15 +299,10 @@
if
(
response
[
i
].
_attachments
.
hasOwnProperty
(
k
))
{
doc
.
_attachments
[
k
]
=
doc
.
_attachments
[
k
]
||
{
"
length
"
:
0
,
"
digest
"
:
""
,
"
content_type
"
:
""
,
};
doc
.
_attachments
[
k
].
length
+=
response
[
i
].
_attachments
[
k
].
length
;
doc
.
_attachments
[
k
].
digest
=
(
doc
.
_attachments
[
k
].
digest
?
doc
.
_attachments
[
k
].
digest
+
"
"
:
""
)
+
response
[
i
].
_attachments
[
k
].
digest
;
doc
.
_attachments
[
k
].
content_type
=
response
[
i
].
_attachments
[
k
].
content_type
;
}
...
...
@@ -317,6 +314,31 @@
});
};
/**
* Gets splited document attachment then returns real attachment data.
*
* @method getAttachment
* @param {Command} command The JIO command
*/
that
.
getAttachment
=
function
(
command
)
{
var
doc
,
option
;
doc
=
command
.
cloneDoc
();
option
=
command
.
cloneOption
();
priv
.
send
(
'
getAttachment
'
,
doc
,
option
,
function
(
err
,
response
)
{
var
i
,
k
;
if
(
err
)
{
err
.
message
=
"
Unable to get attachment
"
;
delete
err
.
index
;
return
that
.
error
(
err
);
}
doc
=
''
;
for
(
i
=
0
;
i
<
response
.
length
;
i
+=
1
)
{
doc
+=
response
[
i
];
}
that
.
success
(
doc
);
});
};
/**
* Removes a document from the sub storages.
*
...
...
@@ -366,6 +388,68 @@
);
};
/**
* Retreive a list of all document in the sub storages.
*
* If include_docs option is false, then it returns the document list from
* the first sub storage. Else, it will merge results and return.
*
* This method support complex queries options.
*
* @method allDocs
* @param {Command} command The JIO command
*/
that
.
allDocs
=
function
(
command
)
{
var
option
=
command
.
cloneOption
(),
result
=
[];
option
=
{
"
include_docs
"
:
option
.
include_docs
};
priv
.
send
(
'
allDocs
'
,
command
.
cloneDoc
(),
option
,
function
(
err
,
response
)
{
var
row
,
j
,
tmp
;
if
(
err
)
{
err
.
message
=
"
Unable to retrieve document list
"
;
delete
err
.
index
;
return
that
.
error
(
err
);
}
function
pop
(
list
,
doc_id
)
{
var
element
;
if
(
!
list
.
dict
)
{
list
.
dict
=
{};
}
if
(
list
.
dict
[
doc_id
])
{
element
=
list
.
dict
[
doc_id
];
delete
list
.
dict
[
doc_id
];
return
element
;
}
while
(
list
.
length
)
{
element
=
list
.
shift
();
if
(
element
.
_id
===
doc_id
)
{
return
element
;
}
else
{
list
.
dict
[
element
.
_id
]
=
element
;
}
}
}
option
=
command
.
cloneOption
();
while
(
response
[
0
].
rows
.
length
)
{
// browsing response[0] rows
row
=
response
[
0
].
rows
.
shift
();
for
(
j
=
1
;
j
<
response
.
length
;
j
+=
1
)
{
// browsing responses
tmp
=
pop
(
response
[
j
].
rows
,
row
.
_id
);
if
(
tmp
!==
undefined
)
{
}
}
}
return
that
.
success
(
response
[
0
]);
}
);
};
return
that
;
}
// end of splitStorage
...
...
@@ -373,6 +457,9 @@
// exports to JIO
if
(
typeof
define
===
"
function
"
&&
define
.
amd
)
{
define
([
'
jio
'
],
function
(
jio
)
{
try
{
queries
=
require
(
'
complex_queries
'
);
}
catch
(
e
)
{};
jio
.
addStorageType
(
'
split
'
,
splitStorage
);
});
}
else
if
(
typeof
require
===
"
function
"
)
{
...
...
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