~lifeless/storm/bug-620615

« back to all changes in this revision

Viewing changes to storm/databases/postgres.py

  • Committer: Gustavo Niemeyer
  • Date: 2006-05-25 20:05:42 UTC
  • Revision ID: gustavo@niemeyer.net-20060525200541-c171f5100ab0a30f
- Implemented MySQL database support! Store tests all pass!
- Splitted out the store tests into per-database files.
- Implemented DateTime, Date, and Time kinds, and support for
  all backends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    @staticmethod
32
32
    def _to_database(value):
33
33
        if isinstance(value, (datetime, date, time)):
34
 
            return value.isoformat()
 
34
            return str(value)
35
35
        return value
36
36
 
37
37
 
53
53
        return self._connection_factory(self, raw_connection)
54
54
 
55
55
 
56
 
def convert_datetime(value):
57
 
    if value is None:
58
 
        return None
59
 
    elif " " in value:
60
 
        # TODO Add suport for timezones.
61
 
        tokens = value.split(".")
62
 
        time_tuple = strptime(tokens[0], "%Y-%m-%d %H:%M:%S")
63
 
        return datetime(*time_tuple[:6]+(int(tokens[1]),))
64
 
    elif ":" in value:
65
 
        tokens = value.split(".")
66
 
        time_tuple = strptime(tokens[0], "%H:%M:%S")
67
 
        return time(*time_tuple[3:6]+(int(tokens[1]),))
68
 
    else:
69
 
        time_tuple = strptime(value, "%Y-%m-%d")
70
 
        return date(*time_tuple[:3])
71
 
 
72
 
psycopg.register_type(psycopg.new_type(psycopg.DATETIME.values,
73
 
                                       "DT", convert_datetime))
 
56
psycopg.register_type(psycopg.new_type(psycopg.DATETIME.values, "DT", str))