site_cubicweb.py 999 Bytes
Newer Older
1

2
from yams import register_base_type
3

4
5
register_base_type('IntArray', ('size',))
register_base_type('FloatArray')
6
7


8
9
from logilab.database import get_db_helper, FunctionDescr
from logilab.database.sqlgen import SQLExpression
10

11
pghelper = get_db_helper('postgres')
12

13
14
15
16
17
18
19
20
21
22
23
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
24
25


26
27
28
29
30
31
## 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

32
33
34
35
36
37
38
39
class VALUE(FunctionDescr):
    minargs = 2
    maxargs = 2
    supported_backends = ('postgres',)
    rtype = 'Float'


register_function(VALUE)