Commit 82a9a0bc authored by Rémi Cardona's avatar Rémi Cardona
Browse files

[RFC] Add proper support for SQLite

parent 9637178eb918
......@@ -21,17 +21,18 @@ 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'
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
sqlitehelper.PYTHON_CONVERTERS['IntArray'] = json.loads
sqlitehelper.PYTHON_CONVERTERS['FloatArray'] = json.loads
## from cubicweb.schema import CONSTRAINTS
......
from yams.buildobjs import EntityType, String
from cubes.array.schema import IntArray, FloatArray
class EntityTypeWithArrays(EntityType):
name = String()
iarray = IntArray()
farray = FloatArray()
......@@ -41,7 +41,18 @@ from cubicweb.devtools import testlib
class DefaultTC(testlib.CubicWebTC):
def test_something(self):
self.skipTest('this cube has no test')
req = self.request()
e = req.create_entity('EntityTypeWithArrays', iarray=range(5),
farray=[float(i) for i in range(5)])
self.commit()
req.drop_entity_cache()
e.cw_clear_all_caches()
self.assertTrue(isinstance(e.iarray, list))
self.assertTrue(isinstance(e.farray, list))
self.assertListEqual(e.iarray, range(5))
self.assertListEqual(e.farray, [float(i) for i in range(5)])
if __name__ == '__main__':
......
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