From b049d03a70a5938f8ae922f3538b606804b22b8f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 22 Sep 2005 05:24:12 +0000 Subject: [PATCH] --- lib/sqlalchemy/types.py | 71 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 lib/sqlalchemy/types.py diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py new file mode 100644 index 0000000000..a138eb4c8c --- /dev/null +++ b/lib/sqlalchemy/types.py @@ -0,0 +1,71 @@ +__ALL__ = [ + 'INT', 'CHAR', 'VARCHAR', 'TEXT', 'FLOAT', 'DECIMAL', + 'TIMESTAMP', 'DATETIME', 'CLOB', 'BLOB', 'BOOLEAN', 'String', 'Integer', 'Numeric', 'DateTime', 'Binary', + ] + + +class TypeEngineMeta(type): + def convert_bind_param(cls, value): + return cls.singleton.convert_bind_param(value) + def convert_result_value(cls, value): + return cls.singleton.convert_result_value(value) + +class TypeEngine(object): + __metaclass__ = TypeEngineMeta + def get_col_spec(self): + raise NotImplementedError() + def convert_bind_param(self, value): + raise NotImplementedError() + def convert_result_value(self, value): + raise NotImplementedError() + +class NullTypeEngine(TypeEngine): + def get_col_spec(self): + raise NotImplementedError() + def convert_bind_param(self, value): + return value + def convert_result_value(self, value): + return value + +class String(TypeEngine): + def __init__(self, length): + self.length = length +String.singleton = String(-1) + +class Integer(TypeEngine): + """integer datatype""" + pass +Integer.singleton = Integer() + +class Numeric(TypeEngine): + def __init__(self, precision, length): + self.precision = precision + self.length = length +Numeric.singleton = Numeric(10, 2) + +class DateTime(TypeEngine): + pass +DateTime.singleton = DateTime() + +class Binary(TypeEngine): + pass +Binary.singleton = Binary() + +class Boolean(TypeEngine): + pass +Boolean.singleton = Boolean() + +class FLOAT(Numeric):pass +class TEXT(String): pass +class DECIMAL(Numeric):pass +class INT(Integer):pass +INTEGER = INT +class TIMESTAMP(DateTime): pass +class DATETIME(DateTime): pass +class CLOB(String): pass +class VARCHAR(String): pass +class CHAR(String):pass +class BLOB(Binary): pass +class BOOLEAN(Boolean): pass + + -- 2.47.2