Skip to content

Commit b2bc219

Browse files
committed
Merge branch claude/add-type-aliases-6uN3E
2 parents cc96f03 + e202818 commit b2bc219

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

docs/src/design/tables/attributes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ libraries, making table definitions more readable and explicit about data precis
8888

8989
| Alias | MySQL Type | Description |
9090
|-------|------------|-------------|
91+
| `bool` | `tinyint` | Boolean value (0 or 1) |
9192
| `int8` | `tinyint` | 8-bit signed integer (-128 to 127) |
9293
| `uint8` | `tinyint unsigned` | 8-bit unsigned integer (0 to 255) |
9394
| `int16` | `smallint` | 16-bit signed integer (-32,768 to 32,767) |
@@ -111,6 +112,7 @@ class Measurement(dj.Manual):
111112
precise_value : float64 # double-precision measurement
112113
sample_count : uint32 # unsigned 32-bit counter
113114
sensor_flags : uint8 # 8-bit status flags
115+
is_valid : bool # boolean flag
114116
"""
115117
```
116118

src/datajoint/declare.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"UINT16": "smallint unsigned",
2929
"INT8": "tinyint",
3030
"UINT8": "tinyint unsigned",
31+
"BOOL": "tinyint",
3132
}
3233
MAX_TABLE_NAME_LENGTH = 64
3334
CONSTANT_LITERALS = {
@@ -50,14 +51,14 @@
5051
UINT16=r"uint16$",
5152
INT8=r"int8$",
5253
UINT8=r"uint8$",
54+
BOOL=r"bool$", # aliased to tinyint
5355
# Native MySQL types
5456
INTEGER=r"((tiny|small|medium|big|)int|integer)(\s*\(.+\))?(\s+unsigned)?(\s+auto_increment)?|serial$",
5557
DECIMAL=r"(decimal|numeric)(\s*\(.+\))?(\s+unsigned)?$",
5658
FLOAT=r"(double|float|real)(\s*\(.+\))?(\s+unsigned)?$",
5759
STRING=r"(var)?char\s*\(.+\)$",
5860
JSON=r"json$",
5961
ENUM=r"enum\s*\(.+\)$",
60-
BOOL=r"bool(ean)?$", # aliased to tinyint(1)
6162
TEMPORAL=r"(date|datetime|time|timestamp|year)(\s*\(.+\))?$",
6263
INTERNAL_BLOB=r"(tiny|small|medium|long|)blob$",
6364
EXTERNAL_BLOB=r"blob@(?P<store>[a-z][\-\w]*)$",

tests/schema_type_aliases.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class TypeAliasTable(dj.Manual):
2222
val_uint16 : uint16 # 16-bit unsigned integer
2323
val_int8 : int8 # 8-bit signed integer
2424
val_uint8 : uint8 # 8-bit unsigned integer
25+
val_bool : bool # boolean value
2526
"""
2627

2728

tests/test_type_aliases.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class TestTypeAliasPatterns:
2525
("uint16", "UINT16"),
2626
("int8", "INT8"),
2727
("uint8", "UINT8"),
28+
("bool", "BOOL"),
2829
],
2930
)
3031
def test_type_alias_pattern_matching(self, alias, expected_category):
@@ -47,6 +48,7 @@ def test_type_alias_pattern_matching(self, alias, expected_category):
4748
("uint16", "smallint unsigned"),
4849
("int8", "tinyint"),
4950
("uint8", "tinyint unsigned"),
51+
("bool", "tinyint"),
5052
],
5153
)
5254
def test_type_alias_mysql_mapping(self, alias, expected_mysql_type):
@@ -107,6 +109,7 @@ def test_heading_preserves_type_aliases(self, schema_type_aliases):
107109
assert "uint16" in heading_str
108110
assert "int8" in heading_str
109111
assert "uint8" in heading_str
112+
assert "bool" in heading_str
110113

111114

112115
class TestTypeAliasInsertFetch:
@@ -129,6 +132,7 @@ def test_insert_and_fetch(self, schema_type_aliases):
129132
val_uint16=65535, # max uint16
130133
val_int8=127, # max int8
131134
val_uint8=255, # max uint8
135+
val_bool=1, # boolean true
132136
)
133137

134138
table.insert1(test_data)
@@ -145,6 +149,7 @@ def test_insert_and_fetch(self, schema_type_aliases):
145149
assert fetched["val_uint16"] == test_data["val_uint16"]
146150
assert fetched["val_int8"] == test_data["val_int8"]
147151
assert fetched["val_uint8"] == test_data["val_uint8"]
152+
assert fetched["val_bool"] == test_data["val_bool"]
148153

149154
def test_insert_primary_key_with_aliases(self, schema_type_aliases):
150155
"""Test using type aliases in primary key."""

0 commit comments

Comments
 (0)