Data types
There are valid data types that you can use with the Meya Database.
Python Type | Database Type | Notes |
---|---|---|
str | String | String is returned as unicode . |
unicode | String | |
int | Number | Number is returned as float .Therefore you should cast to int: int(value) |
float | Number | |
decimal.Decimal | Number | Number is returned as float .Therefore you should cast to int: decimal.Decimal(value) |
bool | Boolean | |
list | List | Note: Number elements are currently returned as decimal.Decimal |
dict | Map | |
None | Null |
# -*- coding: utf-8 -*-
from meya import Component
import decimal
class TestDataTypes(Component):
def start(self):
self.db.flow.set('str', str('abc'))
self.db.flow.set('unicode', u'abc')
self.db.flow.set('int', int(12))
self.db.flow.set('float', float(12))
self.db.flow.set('decimal.Decimal', decimal.Decimal(12))
self.db.flow.set('bool', bool(True))
self.db.flow.set('list', ['a', 'b', 'c', 1, 2])
self.db.flow.set('dict', {'a': 1, 'b': True, 'c': "cool"})
self.db.flow.set('None', None)
# show the resulting data
for key, val in self.db.flow.all().iteritems():
print key, val
return self.respond()
None None
str abc
int 12.0
float 12.0
list [u'a', u'b', u'c', Decimal('1'), Decimal('2')]
id _Rxxxxxxxxxxxx
bool True
unicode abc
decimal.Decimal 12.0
foo bar
bot_id _B9ppDRMoGlW
dict {u'a': 1.0, u'c': u'cool', u'b': True}
Updated over 5 years ago