Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
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
Aurélien Vermylen
jio
Commits
7f71dd30
Commit
7f71dd30
authored
Oct 09, 2017
by
Vincent Bechu
Committed by
Vincent Bechu
Oct 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[querystorage] add spec schema to use key_schema
parent
fdcb654c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
129 additions
and
5 deletions
+129
-5
src/jio.storage/querystorage.js
src/jio.storage/querystorage.js
+27
-4
test/jio.storage/querystorage.tests.js
test/jio.storage/querystorage.tests.js
+102
-1
No files found.
src/jio.storage/querystorage.js
View file @
7f71dd30
/*jslint nomen: true*/
/*jslint nomen: true*/
/*global RSVP*/
/*global RSVP
, jiodate
*/
(
function
(
jIO
,
RSVP
)
{
(
function
(
jIO
,
RSVP
,
jiodate
)
{
"
use strict
"
;
"
use strict
"
;
function
dateType
(
str
)
{
return
jiodate
.
JIODate
(
new
Date
(
str
).
toISOString
());
}
function
initKeySchema
(
storage
,
spec
)
{
var
property
;
for
(
property
in
spec
.
schema
)
{
if
(
spec
.
schema
.
hasOwnProperty
(
property
))
{
if
(
spec
.
schema
[
property
].
type
===
"
string
"
&&
spec
.
schema
[
property
].
format
===
"
date-time
"
)
{
storage
.
_key_schema
.
key_set
[
property
]
=
{
read_from
:
property
,
cast_to
:
"
dateType
"
};
if
(
storage
.
_key_schema
.
cast_lookup
.
dateType
===
undefined
)
{
storage
.
_key_schema
.
cast_lookup
.
dateType
=
dateType
;
}
}
}
}
}
/**
/**
* The jIO QueryStorage extension
* The jIO QueryStorage extension
*
*
...
@@ -11,7 +33,8 @@
...
@@ -11,7 +33,8 @@
*/
*/
function
QueryStorage
(
spec
)
{
function
QueryStorage
(
spec
)
{
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
this
.
_key_schema
=
spec
.
key_schema
;
this
.
_key_schema
=
{
key_set
:
{},
cast_lookup
:
{}};
initKeySchema
(
this
,
spec
);
}
}
QueryStorage
.
prototype
.
get
=
function
()
{
QueryStorage
.
prototype
.
get
=
function
()
{
...
@@ -211,4 +234,4 @@
...
@@ -211,4 +234,4 @@
jIO
.
addStorage
(
'
query
'
,
QueryStorage
);
jIO
.
addStorage
(
'
query
'
,
QueryStorage
);
}(
jIO
,
RSVP
));
}(
jIO
,
RSVP
,
jiodate
));
test/jio.storage/querystorage.tests.js
View file @
7f71dd30
/*jslint nomen: true*/
/*jslint nomen: true*/
/*global Blob*/
/*global Blob
, jiodate
*/
(
function
(
jIO
,
QUnit
,
Blob
)
{
(
function
(
jIO
,
QUnit
,
Blob
)
{
"
use strict
"
;
"
use strict
"
;
var
test
=
QUnit
.
test
,
var
test
=
QUnit
.
test
,
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
test
(
"
create substorage
"
,
function
()
{
test
(
"
create substorage
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
query
"
,
type
:
"
query
"
,
schema
:
{
'
date
'
:
{
type
:
'
string
'
,
format
:
'
date-time
'
}},
sub_storage
:
{
sub_storage
:
{
type
:
"
querystorage200
"
type
:
"
querystorage200
"
}
}
...
@@ -34,6 +35,13 @@
...
@@ -34,6 +35,13 @@
ok
(
jio
.
__storage
.
_sub_storage
instanceof
jio
.
constructor
);
ok
(
jio
.
__storage
.
_sub_storage
instanceof
jio
.
constructor
);
equal
(
jio
.
__storage
.
_sub_storage
.
__type
,
"
querystorage200
"
);
equal
(
jio
.
__storage
.
_sub_storage
.
__type
,
"
querystorage200
"
);
deepEqual
(
jio
.
__storage
.
_key_schema
.
key_set
,
{
"
date
"
:
{
"
cast_to
"
:
"
dateType
"
,
"
read_from
"
:
"
date
"
}
},
'
check key_schema
'
);
ok
(
typeof
jio
.
__storage
.
_key_schema
.
cast_lookup
.
dateType
===
'
function
'
);
});
});
...
@@ -823,6 +831,99 @@
...
@@ -823,6 +831,99 @@
});
});
});
});
test
(
"
manual query used and use schema
"
,
function
()
{
stop
();
expect
(
4
);
function
StorageSchemaCapacity
()
{
return
this
;
}
StorageSchemaCapacity
.
prototype
.
get
=
function
(
id
)
{
var
doc
=
{
title
:
id
,
id
:
"
ID
"
+
id
,
"
another
"
:
"
property
"
};
if
(
id
===
"
foo
"
)
{
equal
(
id
,
"
foo
"
,
"
Get foo
"
);
doc
.
modification_date
=
"
Fri, 08 Sep 2017 07:46:27 +0000
"
;
}
else
{
equal
(
id
,
"
bar
"
,
"
Get bar
"
);
doc
.
modification_date
=
"
Thu, 07 Sep 2017 18:59:23 +0000
"
;
}
return
doc
;
};
StorageSchemaCapacity
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
if
((
capacity
===
"
list
"
))
{
return
true
;
}
return
false
;
};
StorageSchemaCapacity
.
prototype
.
buildQuery
=
function
(
options
)
{
deepEqual
(
options
,
{},
"
No query parameter
"
);
var
result2
=
[{
id
:
"
foo
"
,
value
:
{}
},
{
id
:
"
bar
"
,
value
:
{}
}];
return
result2
;
};
jIO
.
addStorage
(
'
querystoragenoschemacapacity
'
,
StorageSchemaCapacity
);
var
jio
=
jIO
.
createJIO
({
type
:
"
query
"
,
schema
:
{
"
modification_date
"
:
{
"
type
"
:
"
string
"
,
"
format
"
:
"
date-time
"
}
},
sub_storage
:
{
type
:
"
querystoragenoschemacapacity
"
}
});
jio
.
allDocs
({
sort_on
:
[[
"
modification_date
"
,
"
descending
"
]],
limit
:
[
0
,
5
],
select_list
:
[
'
modification_date
'
]
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
data
:
{
rows
:
[
{
id
:
"
foo
"
,
doc
:
{},
value
:
{
modification_date
:
"
Fri, 08 Sep 2017 07:46:27 +0000
"
}
},
{
id
:
"
bar
"
,
doc
:
{},
value
:
{
modification_date
:
"
Thu, 07 Sep 2017 18:59:23 +0000
"
}
}
],
total_rows
:
2
}
});
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// queryStorage.repair
// queryStorage.repair
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
...
...
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