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
dd1743bb
Commit
dd1743bb
authored
Dec 01, 2016
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mappingstorage: add default_property feature
parent
4c7d58a7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
213 additions
and
14 deletions
+213
-14
src/jio.storage/mappingstorage.js
src/jio.storage/mappingstorage.js
+64
-13
test/jio.storage/mappingstorage.tests.js
test/jio.storage/mappingstorage.tests.js
+149
-1
No files found.
src/jio.storage/mappingstorage.js
View file @
dd1743bb
...
...
@@ -95,9 +95,49 @@
return
storage
.
_sub_storage
.
allDocs
({
"
query
"
:
query
,
"
sort_on
"
:
storage
.
_query
.
sort_on
,
"
select_list
"
:
storage
.
_query
.
select_list
,
"
limit
"
:
storage
.
_query
.
limit
})
.
push
(
function
(
data
)
{
if
(
data
.
data
.
rows
.
length
===
0
&&
storage
.
_mapping_dict
.
id
.
default_property
)
{
query
=
new
SimpleQuery
({
key
:
storage
.
_mapping_dict
.
id
.
default_property
,
value
:
id
,
type
:
"
simple
"
});
if
(
storage
.
_query
.
query
!==
undefined
)
{
query
=
new
ComplexQuery
({
operator
:
"
AND
"
,
query_list
:
[
query
,
storage
.
_query
.
query
],
type
:
"
complex
"
});
}
query
=
Query
.
objectToSearchText
(
query
);
return
storage
.
_sub_storage
.
allDocs
({
"
query
"
:
query
,
"
select_list
"
:
[
storage
.
_mapping_dict
.
id
.
equal
],
"
sort_on
"
:
storage
.
_query
.
sort_on
,
"
limit
"
:
storage
.
_query
.
limit
})
.
push
(
function
(
data
)
{
var
i
,
rows
=
[],
orig_rows
=
data
.
data
.
rows
;
if
(
orig_rows
.
length
>
1
)
{
for
(
i
=
0
;
i
<
orig_rows
.
length
;
i
+=
1
)
{
if
(
!
orig_rows
[
i
].
value
[
storage
.
_mapping_dict
.
id
.
equal
])
{
rows
.
push
(
orig_rows
[
i
]);
}
}
data
.
data
.
rows
=
rows
;
}
return
data
;
});
}
return
data
;
})
.
push
(
function
(
data
)
{
if
(
data
.
data
.
rows
.
length
===
0
)
{
throw
new
jIO
.
util
.
jIOError
(
...
...
@@ -120,13 +160,14 @@
}
function
mapToSubProperty
(
storage
,
property
,
sub_doc
,
doc
)
{
if
(
storage
.
_mapping_dict
[
property
]
!==
undefined
)
{
if
(
storage
.
_mapping_dict
[
property
].
equal
!==
undefined
)
{
sub_doc
[
storage
.
_mapping_dict
[
property
].
equal
]
=
doc
[
property
];
return
storage
.
_mapping_dict
[
property
].
equal
;
var
sub_property
=
storage
.
_mapping_dict
[
property
];
if
(
sub_property
!==
undefined
)
{
if
(
sub_property
.
equal
!==
undefined
)
{
sub_doc
[
sub_property
.
equal
]
=
doc
[
property
];
return
sub_property
.
equal
;
}
if
(
s
torage
.
_mapping_dict
[
property
]
.
default_value
!==
undefined
)
{
sub_doc
[
property
]
=
s
torage
.
_mapping_dict
[
property
]
.
default_value
;
if
(
s
ub_property
.
default_value
!==
undefined
)
{
sub_doc
[
property
]
=
s
ub_property
.
default_value
;
return
property
;
}
}
...
...
@@ -145,14 +186,21 @@
}
function
mapToMainProperty
(
storage
,
property
,
sub_doc
,
doc
)
{
if
(
storage
.
_mapping_dict
[
property
]
!==
undefined
)
{
if
(
storage
.
_mapping_dict
[
property
].
equal
!==
undefined
)
{
if
(
sub_doc
.
hasOwnProperty
(
storage
.
_mapping_dict
[
property
].
equal
))
{
doc
[
property
]
=
sub_doc
[
storage
.
_mapping_dict
[
property
].
equal
];
var
main_property
=
storage
.
_mapping_dict
[
property
];
if
(
main_property
!==
undefined
)
{
if
(
main_property
.
equal
!==
undefined
)
{
if
(
sub_doc
.
hasOwnProperty
(
main_property
.
equal
))
{
doc
[
property
]
=
sub_doc
[
main_property
.
equal
];
return
main_property
.
equal
;
}
return
storage
.
_mapping_dict
[
property
].
equal
;
if
(
main_property
.
default_property
&&
sub_doc
.
hasOwnProperty
(
main_property
.
default_property
))
{
doc
[
property
]
=
sub_doc
[
main_property
.
default_property
];
return
main_property
.
default_property
;
}
return
main_property
.
equal
;
}
if
(
storage
.
_mapping_dict
[
property
]
.
default_value
!==
undefined
)
{
if
(
main_property
.
default_value
!==
undefined
)
{
return
property
;
}
}
...
...
@@ -433,6 +481,9 @@
}
if
(
this
.
_id_is_mapped
)
{
select_list
.
push
(
this
.
_mapping_dict
.
id
.
equal
);
if
(
this
.
_mapping_dict
.
id
.
default_property
)
{
select_list
.
push
(
this
.
_mapping_dict
.
id
.
default_property
);
}
}
if
(
option
.
query
!==
undefined
)
{
query
=
mapQuery
(
QueryFactory
.
create
(
option
.
query
));
...
...
test/jio.storage/mappingstorage.tests.js
View file @
dd1743bb
...
...
@@ -9,7 +9,8 @@
expect
=
QUnit
.
expect
,
deepEqual
=
QUnit
.
deepEqual
,
equal
=
QUnit
.
equal
,
module
=
QUnit
.
module
;
module
=
QUnit
.
module
,
count_of_run
;
/////////////////////////////////////////////////////////////////
// Custom test substorage definition
...
...
@@ -169,6 +170,60 @@
});
});
test
(
"
get with id and props mapped (id use default_property)
"
,
function
()
{
stop
();
expect
(
4
);
count_of_run
=
1
;
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
sub_storage
:
{
type
:
"
mappingstorage2713
"
},
mapping_dict
:
{
"
title
"
:
{
"
equal
"
:
"
otherTitle
"
},
"
id
"
:
{
"
equal
"
:
"
otherId
"
,
"
default_property
"
:
"
otherOtherId
"
}
}
});
Storage2713
.
prototype
.
hasCapacity
=
function
()
{
return
true
;
};
Storage2713
.
prototype
.
buildQuery
=
function
(
options
)
{
if
(
count_of_run
===
1
)
{
count_of_run
+=
1
;
equal
(
options
.
query
,
'
otherId: "42"
'
,
"
allDoc 2713 called firstly
"
);
return
[];
}
if
(
count_of_run
===
2
)
{
equal
(
options
.
query
,
'
otherOtherId: "42"
'
,
"
allDoc 2713 called secondary
"
);
return
[{
id
:
"
2713
"
}];
}
};
Storage2713
.
prototype
.
get
=
function
(
id
)
{
equal
(
id
,
"
2713
"
,
"
get 2713 called
"
);
return
{
"
otherTitle
"
:
"
foo
"
};
};
jio
.
get
(
"
42
"
)
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
title
"
:
"
foo
"
});
}).
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
get with id mapped and query
"
,
function
()
{
stop
();
expect
(
3
);
...
...
@@ -1302,6 +1357,99 @@
});
});
test
(
"
allDocs id and prop mapped and query and default_property used
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
mapping_dict
:
{
"
id
"
:
{
"
equal
"
:
"
otherId
"
,
"
default_property
"
:
"
otherOtherId
"
},
"
title
"
:
{
"
equal
"
:
"
otherTitle
"
}
},
sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
}
}
}
});
jio
.
put
(
"
42
"
,
{
"
title
"
:
"
foo
"
,
"
smth
"
:
"
bar
"
,
"
otherOtherId
"
:
"
43
"
})
.
push
(
function
()
{
//return jio.put(43,)
return
jio
.
__storage
.
_sub_storage
.
__storage
.
_sub_storage
.
__storage
.
_sub_storage
.
put
(
'
zzz
'
,
{
"
otherOtherId
"
:
"
43
"
,
"
otherTitle
"
:
"
shrek
"
});
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
'
title: "foo"
'
,
select_list
:
[
"
title
"
]
});
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
data
"
:
{
"
rows
"
:
[
{
"
id
"
:
"
42
"
,
"
value
"
:
{
"
otherOtherId
"
:
"
43
"
,
"
title
"
:
"
foo
"
},
"
doc
"
:
{}
}
],
"
total_rows
"
:
1
}
},
"
allDocs check
"
);
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
'
title: "shrek"
'
,
select_list
:
[
"
title
"
]
});
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
data
"
:
{
"
rows
"
:
[
{
"
id
"
:
"
43
"
,
"
value
"
:
{
"
title
"
:
"
shrek
"
},
"
doc
"
:
{}
}
],
"
total_rows
"
:
1
}
},
"
allDocs check default_property
"
);
})
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// mappingStorage.bulk
/////////////////////////////////////////////////////////////////
...
...
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