Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio-main
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
Hardik Juneja
jio-main
Commits
d4671ec4
Commit
d4671ec4
authored
Oct 21, 2016
by
Vincent Bechu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mappingstorage: fix map_all_property and add a test on buildQuery
parent
b076d049
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
54 deletions
+108
-54
src/jio.storage/mappingstorage.js
src/jio.storage/mappingstorage.js
+52
-54
test/jio.storage/mappingstorage.tests.js
test/jio.storage/mappingstorage.tests.js
+56
-0
No files found.
src/jio.storage/mappingstorage.js
View file @
d4671ec4
...
@@ -57,15 +57,15 @@
...
@@ -57,15 +57,15 @@
});
});
}
}
function
getSubStorageId
(
storage
,
i
ndex
)
{
function
getSubStorageId
(
storage
,
i
d
)
{
var
query
;
var
query
;
return
new
RSVP
.
Queue
()
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
if
(
!
storage
.
_id_is_mapped
)
{
if
(
!
storage
.
_id_is_mapped
||
id
===
undefined
)
{
return
i
ndex
;
return
i
d
;
}
}
if
(
storage
.
_mapping_dict
.
id
.
equal
!==
undefined
)
{
if
(
storage
.
_mapping_dict
.
id
.
equal
!==
undefined
)
{
query
=
storage
.
_mapping_dict
.
id
.
equal
+
'
: "
'
+
i
ndex
+
'
"
'
;
query
=
storage
.
_mapping_dict
.
id
.
equal
+
'
: "
'
+
i
d
+
'
"
'
;
if
(
storage
.
_query
.
query
!==
undefined
)
{
if
(
storage
.
_query
.
query
!==
undefined
)
{
query
+=
'
AND
'
+
storage
.
_query
.
query
;
query
+=
'
AND
'
+
storage
.
_query
.
query
;
}
}
...
@@ -80,7 +80,8 @@
...
@@ -80,7 +80,8 @@
return
undefined
;
return
undefined
;
}
}
if
(
data
.
data
.
rows
.
length
>
1
)
{
if
(
data
.
data
.
rows
.
length
>
1
)
{
throw
new
TypeError
(
"
id must be unique field
"
);
throw
new
TypeError
(
"
id must be unique field:
"
+
id
+
"
, result:
"
+
data
.
data
.
rows
.
toString
());
}
}
return
data
.
data
.
rows
[
0
].
id
;
return
data
.
data
.
rows
[
0
].
id
;
});
});
...
@@ -108,20 +109,24 @@
...
@@ -108,20 +109,24 @@
}
}
function
mapProperty
(
storage
,
property
,
doc
,
mapped_doc
)
{
function
mapProperty
(
storage
,
property
,
doc
,
mapped_doc
)
{
if
(
storage
.
_mapping_dict
[
property
]
!==
undefined
)
{
if
(
storage
.
_mapping_dict
[
property
].
equal
!==
undefined
)
{
if
(
storage
.
_mapping_dict
[
property
].
equal
!==
undefined
)
{
if
(
doc
.
hasOwnProperty
(
storage
.
_mapping_dict
[
property
].
equal
))
{
if
(
doc
.
hasOwnProperty
(
storage
.
_mapping_dict
[
property
].
equal
))
{
mapped_doc
[
property
]
=
doc
[
storage
.
_mapping_dict
[
property
].
equal
];
mapped_doc
[
property
]
=
doc
[
storage
.
_mapping_dict
[
property
].
equal
];
return
storage
.
_mapping_dict
[
property
].
equal
;
}
}
return
;
return
storage
.
_mapping_dict
[
property
].
equal
;
}
}
if
(
storage
.
_mapping_dict
[
property
].
default_value
!==
undefined
)
{
if
(
storage
.
_mapping_dict
[
property
].
default_value
!==
undefined
)
{
return
property
;
return
property
;
}
}
throw
new
jIO
.
util
.
jIOError
(
}
"
Unsuported option(s):
"
+
storage
.
_mapping_dict
[
property
],
if
(
storage
.
_map_all_property
)
{
400
if
(
doc
.
hasOwnProperty
(
property
))
{
);
mapped_doc
[
property
]
=
doc
[
property
];
}
return
property
;
}
return
false
;
}
}
function
mapDocument
(
storage
,
doc
,
delete_id
)
{
function
mapDocument
(
storage
,
doc
,
delete_id
)
{
...
@@ -168,21 +173,19 @@
...
@@ -168,21 +173,19 @@
return
doc
;
return
doc
;
}
}
MappingStorage
.
prototype
.
get
=
function
(
i
ndex
)
{
MappingStorage
.
prototype
.
get
=
function
(
i
d
)
{
var
that
=
this
;
var
that
=
this
;
if
(
index
!==
undefined
)
{
return
getSubStorageId
(
this
,
id
)
return
getSubStorageId
(
this
,
index
)
.
push
(
function
(
id_mapped
)
{
.
push
(
function
(
id
)
{
return
that
.
_sub_storage
.
get
(
id_mapped
);
if
(
id
!==
undefined
)
{
return
that
.
_sub_storage
.
get
(
id
);
}
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
+
index
,
404
);
})
})
.
push
(
function
(
doc
)
{
.
push
(
function
(
doc
)
{
return
mapDocument
(
that
,
doc
,
true
);
return
mapDocument
(
that
,
doc
,
true
);
})
.
push
(
undefined
,
function
(
error
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
+
id
+
"
, cause:
"
+
error
.
message
,
404
);
});
});
}
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
+
index
,
404
);
};
};
MappingStorage
.
prototype
.
post
=
function
(
doc_mapped
)
{
MappingStorage
.
prototype
.
post
=
function
(
doc_mapped
)
{
...
@@ -194,32 +197,35 @@
...
@@ -194,32 +197,35 @@
}
}
};
};
MappingStorage
.
prototype
.
put
=
function
(
i
ndex
,
doc
)
{
MappingStorage
.
prototype
.
put
=
function
(
i
d
,
doc
)
{
var
that
=
this
,
var
that
=
this
,
mapped_doc
=
unmapDocument
(
this
,
doc
);
mapped_doc
=
unmapDocument
(
this
,
doc
);
return
getSubStorageId
(
this
,
i
ndex
)
return
getSubStorageId
(
this
,
i
d
)
.
push
(
function
(
id
)
{
.
push
(
function
(
id
_mapped
)
{
if
(
that
.
_id_is_mapped
)
{
if
(
that
.
_id_is_mapped
)
{
mapped_doc
[
that
.
_mapping_dict
.
id
.
equal
]
=
i
ndex
;
mapped_doc
[
that
.
_mapping_dict
.
id
.
equal
]
=
i
d
;
}
}
if
(
id
!
==
undefined
)
{
if
(
id
=
==
undefined
)
{
return
that
.
_sub_storage
.
put
(
id
,
mapped_doc
);
throw
new
Error
(
);
}
}
return
that
.
_sub_storage
.
put
(
id_mapped
,
mapped_doc
);
})
.
push
(
undefined
,
function
()
{
return
that
.
_sub_storage
.
post
(
mapped_doc
);
return
that
.
_sub_storage
.
post
(
mapped_doc
);
})
})
.
push
(
function
()
{
.
push
(
function
()
{
return
i
ndex
;
return
i
d
;
});
});
};
};
MappingStorage
.
prototype
.
remove
=
function
(
i
ndex
)
{
MappingStorage
.
prototype
.
remove
=
function
(
i
d
)
{
var
that
=
this
;
var
that
=
this
;
return
getSubStorageId
(
this
,
i
ndex
)
return
getSubStorageId
(
this
,
i
d
)
.
push
(
function
(
id
)
{
.
push
(
function
(
id
_mapped
)
{
return
that
.
_sub_storage
.
remove
(
id
);
return
that
.
_sub_storage
.
remove
(
id
_mapped
);
})
})
.
push
(
function
()
{
.
push
(
function
()
{
return
i
ndex
;
return
i
d
;
});
});
};
};
...
@@ -342,10 +348,9 @@
...
@@ -342,10 +348,9 @@
if
(
option
.
sort_on
!==
undefined
)
{
if
(
option
.
sort_on
!==
undefined
)
{
for
(
i
=
0
;
i
<
option
.
sort_on
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
option
.
sort_on
.
length
;
i
+=
1
)
{
property
=
[
this
.
_mapping_dict
[
option
.
sort_on
[
i
][
0
]].
equal
,
property
=
mapProperty
(
this
,
option
.
sort_on
[
i
][
0
],
{},
{});
option
.
sort_on
[
i
][
1
]];
if
(
property
&&
sort_on
.
indexOf
(
property
)
<
0
)
{
if
(
sort_on
.
indexOf
(
property
)
<
0
)
{
select_list
.
push
([
property
,
option
.
sort_on
[
i
][
1
]]);
sort_on
.
push
(
property
);
}
}
}
}
}
}
...
@@ -359,15 +364,8 @@
...
@@ -359,15 +364,8 @@
}
}
if
(
option
.
select_list
!==
undefined
)
{
if
(
option
.
select_list
!==
undefined
)
{
for
(
i
=
0
;
i
<
option
.
select_list
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
option
.
select_list
.
length
;
i
+=
1
)
{
property
=
false
;
property
=
mapProperty
(
this
,
option
.
select_list
[
i
],
{},
{});
if
(
this
.
_mapping_dict
.
hasOwnProperty
(
option
.
select_list
[
i
]))
{
if
(
property
&&
select_list
.
indexOf
(
property
)
<
0
)
{
property
=
this
.
_mapping_dict
[
option
.
select_list
[
i
]].
equal
;
}
else
{
if
(
this
.
_map_all_property
)
{
property
=
option
.
select_list
[
i
];
}
}
if
(
property
&&
sort_on
.
indexOf
(
property
)
<
0
)
{
select_list
.
push
(
property
);
select_list
.
push
(
property
);
}
}
}
}
...
@@ -407,7 +405,7 @@
...
@@ -407,7 +405,7 @@
for
(
i
=
0
;
i
<
result
.
data
.
total_rows
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
result
.
data
.
total_rows
;
i
+=
1
)
{
result
.
data
.
rows
[
i
].
value
=
result
.
data
.
rows
[
i
].
value
=
mapDocument
(
that
,
result
.
data
.
rows
[
i
].
value
,
false
);
mapDocument
(
that
,
result
.
data
.
rows
[
i
].
value
,
false
);
if
(
result
.
data
.
rows
[
i
].
id
!==
undefined
)
{
if
(
result
.
data
.
rows
[
i
].
id
!==
undefined
&&
that
.
_id_is_mapped
)
{
result
.
data
.
rows
[
i
].
id
=
result
.
data
.
rows
[
i
].
id
=
result
.
data
.
rows
[
i
].
value
.
id
;
result
.
data
.
rows
[
i
].
value
.
id
;
delete
result
.
data
.
rows
[
i
].
value
.
id
;
delete
result
.
data
.
rows
[
i
].
value
.
id
;
...
...
test/jio.storage/mappingstorage.tests.js
View file @
d4671ec4
...
@@ -656,6 +656,62 @@
...
@@ -656,6 +656,62 @@
// mappingStorage.allDocs
// mappingStorage.allDocs
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
module
(
"
mappingStorage.buildQuery
"
);
module
(
"
mappingStorage.buildQuery
"
);
test
(
"
allDocs with complex query, with map_all_property
"
,
function
()
{
stop
();
expect
(
1
);
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
}
}
},
map_all_property
:
true
});
jio
.
put
(
"
42
"
,
{
"
title
"
:
"
foo
"
,
"
smth
"
:
"
bar
"
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
'
(title: "foo") AND (smth: "bar")
'
,
select_list
:
[
"
title
"
,
"
smth
"
],
sort_on
:
[[
"
title
"
,
"
descending
"
]]
});
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
data
"
:
{
"
rows
"
:
[
{
"
id
"
:
"
42
"
,
"
value
"
:
{
"
title
"
:
"
foo
"
,
"
smth
"
:
"
bar
"
},
"
doc
"
:
{}
}
],
"
total_rows
"
:
1
}
},
"
allDocs check
"
);
})
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
allDocs with complex query, id and prop mapped
"
,
function
()
{
test
(
"
allDocs with complex query, id and prop mapped
"
,
function
()
{
stop
();
stop
();
expect
(
1
);
expect
(
1
);
...
...
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