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
Boris Kocherov
jio
Commits
b7c65ab7
Commit
b7c65ab7
authored
Aug 30, 2016
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add memoryindexstorage
parent
4046dd5d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
173 additions
and
0 deletions
+173
-0
Gruntfile.js
Gruntfile.js
+1
-0
src/jio.storage/memoryindexstorage.js
src/jio.storage/memoryindexstorage.js
+172
-0
No files found.
Gruntfile.js
View file @
b7c65ab7
...
@@ -168,6 +168,7 @@ module.exports = function (grunt) {
...
@@ -168,6 +168,7 @@ module.exports = function (grunt) {
'
src/jio.storage/replicatestorage.js
'
,
'
src/jio.storage/replicatestorage.js
'
,
'
src/jio.storage/shastorage.js
'
,
'
src/jio.storage/shastorage.js
'
,
'
src/jio.storage/uuidstorage.js
'
,
'
src/jio.storage/uuidstorage.js
'
,
'
src/jio.storage/memoryindexstorage.js
'
,
'
src/jio.storage/memorystorage.js
'
,
'
src/jio.storage/memorystorage.js
'
,
'
src/jio.storage/zipstorage.js
'
,
'
src/jio.storage/zipstorage.js
'
,
'
src/jio.storage/dropboxstorage.js
'
,
'
src/jio.storage/dropboxstorage.js
'
,
...
...
src/jio.storage/memoryindexstorage.js
0 → 100644
View file @
b7c65ab7
/*jslint nomen: true*/
/*global RSVP, FileReader*/
// JIO MemoryIndex Storage Description :
//defenition = {
// type: "memoryindex",
// index: {
// property_id1: null,
// property_id2: function (obj) {
// if (!obj.property_id1) {
// return obj.property_id2;
// }
// }
// },
// sub_storage: {}
//};
(
function
(
jIO
,
RSVP
)
{
"
use strict
"
;
/**
* The jIO MemoryIndex extension
*
* @class MemoryIndex
* @constructor
*/
function
substorage
(
method_name
)
{
return
function
()
{
return
this
.
_sub_storage
[
method_name
].
apply
(
this
.
_sub_storage
,
arguments
);
};
}
function
get_value
(
obj
,
property_name
)
{
var
value
;
if
(
property_name
.
constructor
===
String
)
{
value
=
obj
[
property_name
];
}
else
{
value
=
property_name
(
obj
);
}
return
value
;
}
function
MemoryIndex
(
spec
)
{
var
indexes
=
spec
.
index
||
{},
_indexes
=
{},
index_name
;
this
.
select_list
=
spec
.
select_list
||
[];
this
.
index
=
indexes
;
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
this
.
_indexes
=
_indexes
;
for
(
index_name
in
indexes
)
{
if
(
indexes
.
hasOwnProperty
(
index_name
))
{
_indexes
[
index_name
]
=
{};
}
}
this
.
memory_reindex
();
}
MemoryIndex
.
prototype
.
memory_reindex
=
function
()
{
var
indexes
=
this
.
index
||
{},
_indexes
=
this
.
_indexes
,
index_name
,
property_name
,
row
,
i
,
value
,
select_list
=
this
.
select_list
.
slice
();
for
(
index_name
in
indexes
)
{
if
(
indexes
.
hasOwnProperty
(
index_name
))
{
select_list
.
push
(
index_name
);
}
}
return
this
.
_sub_storage
.
allDocs
({
select_list
:
select_list
})
.
push
(
function
(
result
)
{
var
index_name
;
for
(
i
=
0
;
i
<
result
.
data
.
total_rows
;
i
+=
1
)
{
row
=
result
.
data
.
rows
[
i
];
for
(
index_name
in
indexes
)
{
if
(
indexes
.
hasOwnProperty
(
index_name
))
{
property_name
=
indexes
[
index_name
]
||
index_name
;
value
=
get_value
(
row
.
value
,
property_name
);
if
(
value
)
{
_indexes
[
index_name
][
value
]
=
row
.
id
;
}
}
}
}
});
};
MemoryIndex
.
prototype
.
_find_key
=
function
(
index_name
,
value
)
{
return
this
.
_indexes
[
index_name
][
value
];
};
MemoryIndex
.
prototype
.
find
=
function
(
index_name
,
value
)
{
var
key
=
this
.
_find_key
(
index_name
,
value
),
queue
;
if
(
key
)
{
queue
=
this
.
_sub_storage
.
get
(
key
)
.
push
(
function
(
data
)
{
data
.
id
=
key
;
return
data
;
});
}
else
{
queue
=
RSVP
.
Queue
()
.
push
(
function
()
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
,
404
);
});
}
return
queue
;
};
MemoryIndex
.
prototype
.
put
=
function
(
key
,
value_to_save
)
{
var
property_name
,
indexes
=
this
.
index
,
_indexes
=
this
.
_indexes
,
value
,
sub_storage
=
this
.
_sub_storage
;
return
sub_storage
.
put
.
apply
(
sub_storage
,
arguments
)
.
push
(
function
()
{
var
index_name
;
for
(
index_name
in
indexes
)
{
if
(
indexes
.
hasOwnProperty
(
index_name
))
{
property_name
=
indexes
[
index_name
]
||
index_name
;
value
=
get_value
(
value_to_save
,
property_name
);
if
(
value
)
{
_indexes
[
index_name
][
value
]
=
key
;
}
}
}
});
};
MemoryIndex
.
prototype
.
remove
=
function
(
key
)
{
var
property_name
,
indexes
=
this
.
index
,
_indexes
=
this
.
_indexes
,
value
,
value_to_remove
,
sub_storage
=
this
.
_sub_storage
;
return
sub_storage
.
get
(
key
)
.
push
(
function
(
result
)
{
value_to_remove
=
result
;
return
sub_storage
.
remove
(
key
);
})
.
push
(
function
()
{
var
index_name
;
for
(
index_name
in
indexes
)
{
if
(
indexes
.
hasOwnProperty
(
index_name
))
{
property_name
=
indexes
[
index_name
]
||
index_name
;
value
=
get_value
(
value_to_remove
,
property_name
);
if
(
value
)
{
delete
_indexes
[
index_name
][
value
];
}
}
}
});
};
MemoryIndex
.
prototype
.
post
=
substorage
(
'
get
'
);
MemoryIndex
.
prototype
.
post
=
substorage
(
'
post
'
);
MemoryIndex
.
prototype
.
repair
=
substorage
(
'
repair
'
);
MemoryIndex
.
prototype
.
allDocs
=
substorage
(
'
allDocs
'
);
MemoryIndex
.
prototype
.
hasCapacity
=
substorage
(
'
hasCapacity
'
);
MemoryIndex
.
prototype
.
buildQuery
=
substorage
(
'
buildQuery
'
);
MemoryIndex
.
prototype
.
allAttachments
=
substorage
(
'
allAttachments
'
);
MemoryIndex
.
prototype
.
getAttachment
=
substorage
(
'
getAttachment
'
);
MemoryIndex
.
prototype
.
putAttachment
=
substorage
(
'
putAttachment
'
);
MemoryIndex
.
prototype
.
removeAttachment
=
substorage
(
'
removeAttachment
'
);
jIO
.
addStorage
(
'
memoryindex
'
,
MemoryIndex
);
}(
jIO
,
RSVP
));
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