ddsql 0.0.3__tar.gz → 0.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ddsql
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: SQL Query Library
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -46,17 +46,17 @@ or create your own by inheriting from `BaseSerializer`.
46
46
 
47
47
  **Serialization Table**
48
48
 
49
- | Python Type | Base | PostgreSQL | ClickHouse |
50
- |----------------------|--------------------------|-------------------------------------|---------------------------------------------------|
51
- | `None` | `NULL` | `NULL` | `NULL` |
52
- | `bool` | `true`/`false` | `true`/`false` | `true`/`false` |
53
- | `int` | `123` | `123` | `123` |
54
- | `float`/`Decimal` | `45.67` | `45.67` | `45.67` |
55
- | `str` | `'value'` | `'value'` | `'value'` |
56
- | `UUID` | `'550e8400-...'` | `'550e8400-...'::uuid` | `toUUID('550e8400-...')` |
57
- | `datetime` | `'2025-01-01T12:00:00'` | `'2025-01-01T12:00:00'::timestamp` | `parseDateTimeBestEffort('2025-01-01T12:00:00')` |
58
- | `date` | `'2025-01-01'` | `'2025-01-01'::date` | `toDate('2025-01-01')` |
59
- | `list`/`tuple`/`set` | `(item1, item2, ...)` | `(item1, item2, ...)` | `(item1, item2, ...)` |
49
+ | Python Type | Base | PostgreSQL | ClickHouse |
50
+ |----------------------|-------------------------|------------------------------------|-------------------------------------------------------|
51
+ | `None` | `NULL` | `NULL` | `NULL` |
52
+ | `bool` | `true`/`false` | `true`/`false` | `true`/`false` |
53
+ | `int` | `123` | `123` | `123` |
54
+ | `float`/`Decimal` | `45.67` | `45.67` | `45.67` |
55
+ | `str` | `'value'` | `'value'` | `'value'` |
56
+ | `UUID` | `'550e8400-...'` | `'550e8400-...'::uuid` | `toUUID('550e8400-...')` |
57
+ | `datetime` | `'2025-01-01T12:00:00'` | `'2025-01-01T12:00:00'::timestamp` | `parseDateTime64BestEffort('2025-01-01T12:00:00', 6)` |
58
+ | `date` | `'2025-01-01'` | `'2025-01-01'::date` | `toDate('2025-01-01')` |
59
+ | `list`/`tuple`/`set` | `(item1, item2, ...)` | `(item1, item2, ...)` | `(item1, item2, ...)` |
60
60
 
61
61
  String values are escaped according to the dialect rules, so quotes, backslashes
62
62
  and control characters cannot break the query:
@@ -70,6 +70,16 @@ and control characters cannot break the query:
70
70
  A NUL (`0x00`) character raises `ValueError`, since PostgreSQL cannot store it in text values.
71
71
 
72
72
  The serialized literal is always a single printable line.
73
+
74
+ `datetime` values keep their microseconds and UTC offset:
75
+
76
+ - `ClickhouseSerializer` renders `parseDateTime64BestEffort('...', 6)`, which yields a `DateTime64(6)`
77
+ literal; a timezone-aware value is converted according to its offset, a naive value is interpreted
78
+ in the server time zone. Inserting such a literal into a `DateTime` column silently truncates it
79
+ to seconds, and comparisons with `DateTime` columns work as expected.
80
+ - `PostgresSerializer` renders a timezone-aware value as `'...+03:00'::timestamptz`, so its offset
81
+ is honoured; a naive value is rendered as `'...'::timestamp`, as before.
82
+
73
83
  To customize escaping in your own serializer, override the `escape_string` method.
74
84
 
75
85
  If you need to serialize a type not listed in the table, override the `serialize_other_object` method in your serializer:
@@ -24,17 +24,17 @@ or create your own by inheriting from `BaseSerializer`.
24
24
 
25
25
  **Serialization Table**
26
26
 
27
- | Python Type | Base | PostgreSQL | ClickHouse |
28
- |----------------------|--------------------------|-------------------------------------|---------------------------------------------------|
29
- | `None` | `NULL` | `NULL` | `NULL` |
30
- | `bool` | `true`/`false` | `true`/`false` | `true`/`false` |
31
- | `int` | `123` | `123` | `123` |
32
- | `float`/`Decimal` | `45.67` | `45.67` | `45.67` |
33
- | `str` | `'value'` | `'value'` | `'value'` |
34
- | `UUID` | `'550e8400-...'` | `'550e8400-...'::uuid` | `toUUID('550e8400-...')` |
35
- | `datetime` | `'2025-01-01T12:00:00'` | `'2025-01-01T12:00:00'::timestamp` | `parseDateTimeBestEffort('2025-01-01T12:00:00')` |
36
- | `date` | `'2025-01-01'` | `'2025-01-01'::date` | `toDate('2025-01-01')` |
37
- | `list`/`tuple`/`set` | `(item1, item2, ...)` | `(item1, item2, ...)` | `(item1, item2, ...)` |
27
+ | Python Type | Base | PostgreSQL | ClickHouse |
28
+ |----------------------|-------------------------|------------------------------------|-------------------------------------------------------|
29
+ | `None` | `NULL` | `NULL` | `NULL` |
30
+ | `bool` | `true`/`false` | `true`/`false` | `true`/`false` |
31
+ | `int` | `123` | `123` | `123` |
32
+ | `float`/`Decimal` | `45.67` | `45.67` | `45.67` |
33
+ | `str` | `'value'` | `'value'` | `'value'` |
34
+ | `UUID` | `'550e8400-...'` | `'550e8400-...'::uuid` | `toUUID('550e8400-...')` |
35
+ | `datetime` | `'2025-01-01T12:00:00'` | `'2025-01-01T12:00:00'::timestamp` | `parseDateTime64BestEffort('2025-01-01T12:00:00', 6)` |
36
+ | `date` | `'2025-01-01'` | `'2025-01-01'::date` | `toDate('2025-01-01')` |
37
+ | `list`/`tuple`/`set` | `(item1, item2, ...)` | `(item1, item2, ...)` | `(item1, item2, ...)` |
38
38
 
39
39
  String values are escaped according to the dialect rules, so quotes, backslashes
40
40
  and control characters cannot break the query:
@@ -48,6 +48,16 @@ and control characters cannot break the query:
48
48
  A NUL (`0x00`) character raises `ValueError`, since PostgreSQL cannot store it in text values.
49
49
 
50
50
  The serialized literal is always a single printable line.
51
+
52
+ `datetime` values keep their microseconds and UTC offset:
53
+
54
+ - `ClickhouseSerializer` renders `parseDateTime64BestEffort('...', 6)`, which yields a `DateTime64(6)`
55
+ literal; a timezone-aware value is converted according to its offset, a naive value is interpreted
56
+ in the server time zone. Inserting such a literal into a `DateTime` column silently truncates it
57
+ to seconds, and comparisons with `DateTime` columns work as expected.
58
+ - `PostgresSerializer` renders a timezone-aware value as `'...+03:00'::timestamptz`, so its offset
59
+ is honoured; a naive value is rendered as `'...'::timestamp`, as before.
60
+
51
61
  To customize escaping in your own serializer, override the `escape_string` method.
52
62
 
53
63
  If you need to serialize a type not listed in the table, override the `serialize_other_object` method in your serializer:
@@ -40,7 +40,9 @@ class ClickhouseSerializer(BaseSerializer):
40
40
 
41
41
  @classmethod
42
42
  def serialize_datetime(cls, value: datetime) -> str:
43
- return f"parseDateTimeBestEffort('{cls.escape_string(value.isoformat())}')"
43
+ # parseDateTimeBestEffort returns DateTime (second precision) and silently drops
44
+ # microseconds; the DateTime64 variant keeps them and honours the UTC offset
45
+ return f"parseDateTime64BestEffort('{cls.escape_string(value.isoformat())}', 6)"
44
46
 
45
47
  @classmethod
46
48
  def serialize_date(cls, value: date) -> str:
@@ -52,7 +52,10 @@ class PostgresSerializer(BaseSerializer):
52
52
 
53
53
  @classmethod
54
54
  def serialize_datetime(cls, value: datetime) -> str:
55
- return f"'{cls.escape_string(value.isoformat())}'::timestamp"
55
+ # `timestamp` ignores the UTC offset of the literal, so a timezone-aware value
56
+ # is rendered as `timestamptz` to keep its offset; naive values are left as-is
57
+ cast = 'timestamptz' if value.tzinfo is not None else 'timestamp'
58
+ return f"'{cls.escape_string(value.isoformat())}'::{cast}"
56
59
 
57
60
  @classmethod
58
61
  def serialize_date(cls, value: date) -> str:
@@ -1,7 +1,7 @@
1
1
  [tool.poetry]
2
2
  name = "ddsql"
3
3
  description = "SQL Query Library"
4
- version = "0.0.3"
4
+ version = "0.0.4"
5
5
  authors = ["davyddd"]
6
6
  license = "MIT"
7
7
  repository = "https://github.com/davyddd/ddsql"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes