Files
tryton/trytond/backend/postgresql/fields.py
T

145 lines
2.6 KiB
Python
Raw Normal View History

2009-02-03 18:58:25 +01:00
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
import psycopg2
2009-10-31 19:33:45 +01:00
from trytond.backend import fields
2009-02-03 18:58:25 +01:00
2009-10-31 19:33:45 +01:00
class Boolean(fields.Boolean):
2009-02-03 18:58:25 +01:00
@staticmethod
def sql_type(field):
return ('bool', 'bool')
2009-10-31 19:33:45 +01:00
class Integer(fields.Integer):
2009-02-03 18:58:25 +01:00
@staticmethod
def sql_type(field):
return ('int4', 'int4')
2009-10-31 19:33:45 +01:00
class BigInteger(fields.BigInteger):
2009-02-03 18:58:25 +01:00
@staticmethod
def sql_type(field):
return ('int8', 'int8')
2009-10-31 19:33:45 +01:00
class Char(fields.Char):
2009-02-03 18:58:25 +01:00
@staticmethod
def sql_type(field):
if field.size:
return ('varchar', 'varchar(%d)' % (field.size,))
return ('varchar', 'varchar')
2009-10-31 19:33:45 +01:00
class Sha(fields.Sha):
2009-02-03 18:58:25 +01:00
@staticmethod
def sql_type(field):
return ('varchar', 'varchar(40)')
2009-10-31 19:33:45 +01:00
class Text(fields.Text):
2009-02-03 18:58:25 +01:00
@staticmethod
def sql_type(field):
return ('text', 'text')
2009-10-31 19:33:45 +01:00
class Float(fields.Float):
2009-02-03 18:58:25 +01:00
@staticmethod
def sql_type(field):
return ('float8', 'float8')
2009-10-31 19:33:45 +01:00
class Numeric(fields.Numeric):
2009-02-03 18:58:25 +01:00
@staticmethod
def sql_type(field):
return ('numeric', 'numeric')
2009-10-31 19:33:45 +01:00
class Date(fields.Date):
2009-02-03 18:58:25 +01:00
@staticmethod
def sql_type(field):
return ('date', 'date')
2009-10-31 19:33:45 +01:00
class DateTime(fields.DateTime):
2009-02-03 18:58:25 +01:00
@staticmethod
def sql_type(field):
return ('timestamp', 'timestamp(0)')
2009-11-10 14:00:13 +01:00
class Timestamp(fields.Timestamp):
@staticmethod
def sql_type(field):
return ('timestamp', 'timestamp(6)')
2009-10-31 19:33:45 +01:00
class Time(fields.Time):
2009-02-03 18:58:25 +01:00
@staticmethod
def sql_type(field):
return ('time', 'time')
2009-10-31 19:33:45 +01:00
class Binary(fields.Binary):
2009-02-03 18:58:25 +01:00
@staticmethod
def sql_format(value):
2009-02-03 18:58:25 +01:00
return value and psycopg2.Binary(value) or None
@staticmethod
def sql_type(field):
return ('bytea', 'bytea')
2009-10-31 19:33:45 +01:00
class Selection(fields.Selection):
2009-02-03 18:58:25 +01:00
@staticmethod
def sql_type(field):
return ('varchar', 'varchar')
2009-10-31 19:33:45 +01:00
class Reference(fields.Reference):
2009-02-03 18:58:25 +01:00
@staticmethod
def sql_type(field):
return ('varchar', 'varchar')
2009-10-31 19:33:45 +01:00
class Many2One(fields.Many2One):
2009-02-03 18:58:25 +01:00
@staticmethod
def sql_type(field):
return ('int4', 'int4')
FIELDS = {
'boolean': Boolean,
'integer': Integer,
'biginteger': BigInteger,
'char': Char,
'sha': Sha,
'text': Text,
'float': Float,
'numeric': Numeric,
'date': Date,
'datetime': DateTime,
2009-11-10 14:00:13 +01:00
'timestamp': Timestamp,
2009-02-03 18:58:25 +01:00
'time': Time,
'binary': Binary,
'selection': Selection,
'reference': Reference,
'many2one': Many2One,
2009-10-31 19:33:45 +01:00
'one2many': fields.One2Many,
'many2many': fields.Many2Many,
'function': fields.Function,
'property': fields.Property,
2009-02-03 18:58:25 +01:00
}