Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubes
array
Commits
008576e89dae
Commit
6ef8d48f
authored
Jul 24, 2013
by
Adrien Di Mascio
Browse files
provide sqlite serializer for arrays (closes #3036179)
parent
2e6f2312d2db
Changes
1
Hide whitespace changes
Inline
Side-by-side
site_cubicweb.py
View file @
008576e8
import
json
from
logilab.database
import
get_db_helper
,
FunctionDescr
from
logilab.database.sqlgen
import
SQLExpression
from
yams
import
register_base_type
register_base_type
(
'IntArray'
,
(
'size'
,))
register_base_type
(
'FloatArray'
)
from
rql.utils
import
register_function
from
logilab.database
import
get_db_helper
,
FunctionDescr
from
logilab.database.sqlgen
import
SQLExpression
register_base_type
(
'IntArray'
,
(
'size'
,))
register_base_type
(
'FloatArray'
)
pghelper
=
get_db_helper
(
'postgres'
)
sqlitehelper
=
get_db_helper
(
'sqlite'
)
def
convert_array
(
values
):
"""converter for Geometry"""
...
...
@@ -17,10 +21,17 @@ def convert_array(values):
# Yams -> SQL type mapping
pghelper
.
TYPE_MAPPING
[
'IntArray'
]
=
'integer[]'
pghelper
.
TYPE_MAPPING
[
'FloatArray'
]
=
'double precision[]'
sqlitehelper
.
TYPE_MAPPING
[
'IntArray'
]
=
'text'
sqlitehelper
.
TYPE_MAPPING
[
'FloatArray'
]
=
'text'
# Python -> SQL conversion
pghelper
.
TYPE_CONVERTERS
[
'IntArray'
]
=
convert_array
pghelper
.
TYPE_CONVERTERS
[
'FloatArray'
]
=
convert_array
# NOTE: there's not way yet to specify the symmetrical operation
# (i.e. deserialization)
sqlitehelper
.
TYPE_CONVERTERS
[
'IntArray'
]
=
json
.
dumps
sqlitehelper
.
TYPE_CONVERTERS
[
'FloatArray'
]
=
json
.
dumps
## from cubicweb.schema import CONSTRAINTS
...
...
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