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
6b695237
Commit
6b695237
authored
Sep 28, 2016
by
Vincent Bechu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mapping storage: create this storage
parent
1ecc04a5
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
722 additions
and
3 deletions
+722
-3
Gruntfile.js
Gruntfile.js
+2
-1
src/jio.storage/mappingstorage.js
src/jio.storage/mappingstorage.js
+201
-0
test/jio.storage/mappingstorage.tests.js
test/jio.storage/mappingstorage.tests.js
+518
-0
test/tests.html
test/tests.html
+1
-2
No files found.
Gruntfile.js
View file @
6b695237
...
...
@@ -180,7 +180,8 @@ module.exports = function (grunt) {
'
src/jio.storage/localstorage.js
'
,
'
src/jio.storage/indexeddbstorage.js
'
,
'
src/jio.storage/cryptstorage.js
'
,
'
src/jio.storage/websqlstorage.js
'
'
src/jio.storage/websqlstorage.js
'
,
'
src/jio.storage/mappingstorage.js
'
],
dest
:
'
dist/<%= pkg.name %>-<%= pkg.version %>.js
'
// dest: 'jio.js'
...
...
src/jio.storage/mappingstorage.js
0 → 100644
View file @
6b695237
/*jslint indent:2, maxlen: 80, nomen: true */
/*global jIO */
(
function
(
jIO
)
{
"
use strict
"
;
function
MappingStorage
(
spec
)
{
this
.
_mapping_dict
=
spec
.
mapping_dict
||
{};
this
.
_default_dict
=
spec
.
default_dict
||
{};
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
}
MappingStorage
.
prototype
.
_getSubStorageId
=
function
(
index
)
{
var
option
=
{};
option
.
query
=
this
.
_mapping_dict
.
id
.
equal
+
'
: "
'
+
index
+
'
"
'
;
return
this
.
_sub_storage
.
allDocs
(
option
)
.
push
(
function
(
data
)
{
return
data
.
data
.
rows
[
0
].
id
;
});
};
MappingStorage
.
prototype
.
_mapDocFromStorage
=
function
(
object
)
{
var
result
=
{},
that
=
this
,
prop
;
for
(
prop
in
that
.
_mapping_dict
)
{
if
(
that
.
_mapping_dict
.
hasOwnProperty
(
prop
))
{
if
(
prop
!==
"
id
"
)
{
result
[
prop
]
=
object
[
that
.
_mapping_dict
[
prop
].
equal
];
}
}
}
return
result
;
};
MappingStorage
.
prototype
.
get
=
function
(
index
)
{
var
that
=
this
;
if
(
this
.
_mapping_dict
.
id
===
undefined
||
this
.
_mapping_dict
.
id
.
equal
===
"
id
"
)
{
return
this
.
_sub_storage
.
get
(
index
)
.
push
(
function
(
result
)
{
return
that
.
_mapDocFromStorage
(
result
);
});
}
return
this
.
_getSubStorageId
(
index
)
.
push
(
function
(
id
)
{
return
that
.
_sub_storage
.
get
(
id
);
})
.
push
(
function
(
result
)
{
return
that
.
_mapDocFromStorage
(
result
);
});
};
MappingStorage
.
prototype
.
put
=
function
(
index
,
doc
)
{
var
prop
,
doc_mapped
=
JSON
.
parse
(
JSON
.
stringify
(
this
.
_default_dict
));
for
(
prop
in
doc
)
{
if
(
doc
.
hasOwnProperty
(
prop
))
{
doc_mapped
[
this
.
_mapping_dict
[
prop
].
equal
]
=
doc
[
prop
];
}
}
if
(
this
.
_mapping_dict
.
id
===
undefined
||
this
.
_mapping_dict
.
id
.
equal
===
"
id
"
)
{
return
this
.
_sub_storage
.
put
(
index
,
doc_mapped
);
}
doc_mapped
[
this
.
_mapping_dict
.
id
.
equal
]
=
index
;
return
this
.
_sub_storage
.
post
(
doc_mapped
)
.
push
(
function
()
{
return
index
;
});
};
MappingStorage
.
prototype
.
remove
=
function
(
index
)
{
var
that
=
this
;
if
(
this
.
_mapping_dict
.
id
===
undefined
||
this
.
_mapping_dict
.
id
.
equal
===
"
id
"
)
{
return
this
.
_sub_storage
.
remove
.
apply
(
this
.
_sub_storage
,
arguments
);
}
return
this
.
_getSubStorageId
(
index
)
.
push
(
function
(
id
)
{
return
that
.
_sub_storage
.
remove
(
id
);
})
.
push
(
function
()
{
return
index
;
});
};
MappingStorage
.
prototype
.
putAttachment
=
function
(
doc_id
)
{
var
that
=
this
;
if
(
this
.
_mapping_dict
.
id
===
undefined
||
this
.
_mapping_dict
.
id
.
equal
===
"
id
"
)
{
return
this
.
_sub_storage
.
putAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
}
return
this
.
_getSubStorageId
(
doc_id
)
.
push
(
function
(
id
)
{
doc_id
=
id
;
return
that
.
_sub_storage
.
putAttachment
.
apply
(
that
.
_sub_storage
,
arguments
);
});
};
MappingStorage
.
prototype
.
getAttachment
=
function
(
doc_id
)
{
var
that
=
this
;
if
(
this
.
_mapping_dict
.
id
===
undefined
||
this
.
_mapping_dict
.
id
.
equal
===
"
id
"
)
{
return
this
.
_sub_storage
.
getAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
}
return
this
.
_getSubStorageId
(
doc_id
)
.
push
(
function
(
id
)
{
doc_id
=
id
;
return
that
.
_sub_storage
.
getAttachment
.
apply
(
that
.
_sub_storage
,
arguments
);
});
};
MappingStorage
.
prototype
.
removeAttachment
=
function
(
doc_id
)
{
var
that
=
this
;
if
(
this
.
_mapping_dict
.
id
===
undefined
||
this
.
_mapping_dict
.
id
.
equal
===
"
id
"
)
{
return
this
.
_sub_storage
.
removeAttachment
.
apply
(
this
.
_sub_storage
,
arguments
);
}
return
this
.
_getSubStorageId
(
doc_id
)
.
push
(
function
(
id
)
{
doc_id
=
id
;
return
that
.
_sub_storage
.
removeAttachment
.
apply
(
that
.
_sub_storage
,
arguments
);
});
};
MappingStorage
.
prototype
.
hasCapacity
=
function
()
{
return
this
.
_sub_storage
.
hasCapacity
.
apply
(
this
.
_sub_storage
,
arguments
);
};
MappingStorage
.
prototype
.
buildQuery
=
function
(
option
)
{
var
that
=
this
,
i
,
select_list
=
[],
sort_on
=
[],
query
;
function
mapQuery
(
one_query
)
{
var
i
,
query_list
=
[];
if
(
one_query
.
type
===
"
complex
"
)
{
for
(
i
=
0
;
i
<
one_query
.
query_list
.
length
;
i
+=
1
)
{
query_list
.
push
(
mapQuery
(
one_query
.
query_list
[
i
]));
}
return
{
operator
:
one_query
.
operator
,
query_list
:
query_list
,
type
:
"
complex
"
};
}
return
{
key
:
that
.
_mapping_dict
[
one_query
.
key
].
equal
,
type
:
"
simple
"
,
value
:
one_query
.
value
};
}
if
(
option
.
sort_on
!==
undefined
)
{
for
(
i
=
0
;
i
<
option
.
sort_on
.
length
;
i
+=
1
)
{
sort_on
.
push
([
this
.
_mapping_dict
[
option
.
sort_on
[
i
][
0
]].
equal
,
option
.
sort_on
[
i
][
1
]]);
}
}
if
(
option
.
select_list
!==
undefined
)
{
for
(
i
=
0
;
i
<
option
.
select_list
.
length
;
i
+=
1
)
{
select_list
.
push
(
this
.
_mapping_dict
[
option
.
select_list
[
i
]].
equal
);
}
}
if
(
this
.
_mapping_dict
.
id
!==
undefined
&&
this
.
_mapping_dict
.
id
.
equal
!==
"
id
"
)
{
select_list
.
push
(
this
.
_mapping_dict
.
id
.
equal
);
}
query
=
jIO
.
Query
.
parseStringToObject
(
option
.
query
);
return
this
.
_sub_storage
.
allDocs
(
{
query
:
mapQuery
(
query
),
select_list
:
select_list
,
sort_on
:
sort_on
,
limit
:
option
.
limit
,
include_docs
:
option
.
include_docs
||
false
}
)
.
push
(
function
(
result
)
{
for
(
i
=
0
;
i
<
result
.
data
.
total_rows
;
i
+=
1
)
{
if
(
that
.
_mapping_dict
.
id
!==
undefined
&&
that
.
_mapping_dict
.
id
.
equal
!==
"
id
"
)
{
result
.
data
.
rows
[
i
].
id
=
result
.
data
.
rows
[
i
].
value
[
that
.
_mapping_dict
.
id
.
equal
];
delete
result
.
data
.
rows
[
i
].
value
[
that
.
_mapping_dict
.
id
.
equal
];
}
result
.
data
.
rows
[
i
].
value
=
that
.
_mapDocFromStorage
(
result
.
data
.
rows
[
i
].
value
);
}
return
result
.
data
.
rows
;
});
};
jIO
.
addStorage
(
'
mapping
'
,
MappingStorage
);
}(
jIO
));
\ No newline at end of file
test/jio.storage/mappingstorage.tests.js
0 → 100644
View file @
6b695237
This diff is collapsed.
Click to expand it.
test/tests.html
View file @
6b695237
...
...
@@ -28,7 +28,6 @@
<script
src=
"queries/key-jiodate.tests.js"
></script>
<!--script src="queries/key-localstorage.tests.js"></script-->
<script
src=
"jio.storage/memorystorage.tests.js"
></script>
<script
src=
"jio.storage/querystorage.tests.js"
></script>
<script
src=
"jio.storage/localstorage.tests.js"
></script>
...
...
@@ -41,7 +40,7 @@
<script
src=
"jio.storage/uuidstorage.tests.js"
></script>
<script
src=
"jio.storage/replicatestorage.tests.js"
></script>
<script
src=
"jio.storage/shastorage.tests.js"
></script>
<script
src=
"jio.storage/mappingstorage.tests.js"
></script>
<!--script src="jio.storage/qiniustorage.tests.js"></script-->
<!--script src="jio.storage/indexstorage.tests.js"></script-->
<script
src=
"jio.storage/cryptstorage.tests.js"
></script>
...
...
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