Commit bcc88237 authored by Sylvain Thénault's avatar Sylvain Thénault

follow api and move custom type init to site_cubicweb

parent 2d87c04c76b2
from yams import register_base_type
register_base_type('IntArray')
register_base_type('FloatArray')
# Add a converter for Geometry
from logilab.database.sqlgen import SQLExpression
def convert_array(values):
return SQLExpression('ARRAY[%s]' % ', '.join([str(x) for x in values]))
# Add the datatype to the helper mapping
from logilab.database import get_db_helper
# Add the datatype to the helper mapping
helper = get_db_helper('postgres')
typemap = helper.TYPE_MAPPING
typemap['IntArray'] = 'integer[]'
typemap['FloatArray'] = 'double[]'
# Add the converter function to the known SQL_CONVERTERS
helper.TYPE_CONVERTERS['IntArray'] = convert_array
helper.TYPE_CONVERTERS['FloatArray'] = convert_array
......@@ -16,6 +16,6 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""cubicweb-postgres-array schema"""
from yams.buildobjs import _make_type
IntArray = _make_type('IntArray')
FloatArray = _make_type('FloatArray')
from yams.buildobjs import make_type
IntArray = make_type('IntArray')
FloatArray = make_type('FloatArray')
from yams import register_base_type
## from cubicweb.schema import CONSTRAINTS
## from cubes.postgis.schema import params
## CONSTRAINTS.update((v.__name__, v) for v in params.values())
register_base_type('IntArray', ('size',))
register_base_type('FloatArray')
from logilab.database import get_db_helper, FunctionDescr
from logilab.database.sqlgen import SQLExpression
from logilab.database import FunctionDescr
pghelper = get_db_helper('postgres')
from rql.utils import register_function
def convert_array(values):
"""converter for Geometry"""
return SQLExpression('ARRAY[%s]' % ', '.join([str(x) for x in values]))
# Yams -> SQL type mapping
pghelper.TYPE_MAPPING['IntArray'] = 'integer[]'
pghelper.TYPE_MAPPING['FloatArray'] = 'double[]'
# Python -> SQL conversion
pghelper.TYPE_CONVERTERS['IntArray'] = convert_array
pghelper.TYPE_CONVERTERS['FloatArray'] = convert_array
## from cubicweb.schema import CONSTRAINTS
## from cubes.postgis.schema import params
## CONSTRAINTS.update((v.__name__, v) for v in params.values())
from rql.utils import register_function
class VALUE(FunctionDescr):
minargs = 2
maxargs = 2
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment