|
9 | 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
10 | 10 | # See the License for the specific language governing permissions and |
11 | 11 | # limitations under the License |
| 12 | +import uuid |
| 13 | + |
12 | 14 | import pytest |
13 | 15 | import sqlalchemy as sqla |
14 | 16 | from sqlalchemy.sql import and_, not_, or_ |
@@ -133,6 +135,60 @@ def test_insert(trino_connection): |
133 | 135 | metadata.drop_all(engine) |
134 | 136 |
|
135 | 137 |
|
| 138 | +@pytest.mark.skipif( |
| 139 | + sqlalchemy_version() < "2.0", |
| 140 | + reason="sqlalchemy.Uuid only exists with SQLAlchemy 2.0 and above" |
| 141 | +) |
| 142 | +@pytest.mark.parametrize('trino_connection', ['memory'], indirect=True) |
| 143 | +def test_define_and_create_table_uuid(trino_connection): |
| 144 | + engine, conn = trino_connection |
| 145 | + if not engine.dialect.has_schema(conn, "test"): |
| 146 | + with engine.begin() as connection: |
| 147 | + connection.execute(sqla.schema.CreateSchema("test")) |
| 148 | + metadata = sqla.MetaData() |
| 149 | + try: |
| 150 | + sqla.Table('users', |
| 151 | + metadata, |
| 152 | + sqla.Column('guid', sqla.Uuid), |
| 153 | + schema="test") |
| 154 | + metadata.create_all(engine) |
| 155 | + assert sqla.inspect(engine).has_table('users', schema="test") |
| 156 | + users = sqla.Table('users', metadata, schema='test', autoload_with=conn) |
| 157 | + assert_column(users, "guid", sqla.sql.sqltypes.Uuid) |
| 158 | + finally: |
| 159 | + metadata.drop_all(engine) |
| 160 | + |
| 161 | + |
| 162 | +@pytest.mark.skipif( |
| 163 | + sqlalchemy_version() < "2.0", |
| 164 | + reason="sqlalchemy.Uuid only exists with SQLAlchemy 2.0 and above" |
| 165 | +) |
| 166 | +@pytest.mark.parametrize('trino_connection', ['memory'], indirect=True) |
| 167 | +def test_insert_uuid(trino_connection): |
| 168 | + engine, conn = trino_connection |
| 169 | + |
| 170 | + if not engine.dialect.has_schema(conn, "test"): |
| 171 | + with engine.begin() as connection: |
| 172 | + connection.execute(sqla.schema.CreateSchema("test")) |
| 173 | + metadata = sqla.MetaData() |
| 174 | + try: |
| 175 | + users = sqla.Table('users', |
| 176 | + metadata, |
| 177 | + sqla.Column('guid', sqla.Uuid), |
| 178 | + schema="test") |
| 179 | + metadata.create_all(engine) |
| 180 | + ins = users.insert() |
| 181 | + guid = uuid.uuid4() |
| 182 | + conn.execute(ins, {"guid": guid}) |
| 183 | + query = sqla.select(users) |
| 184 | + result = conn.execute(query) |
| 185 | + rows = result.fetchall() |
| 186 | + assert len(rows) == 1 |
| 187 | + assert rows[0] == (guid,) |
| 188 | + finally: |
| 189 | + metadata.drop_all(engine) |
| 190 | + |
| 191 | + |
136 | 192 | @pytest.mark.skipif( |
137 | 193 | sqlalchemy_version() < "1.4", |
138 | 194 | reason="columns argument to select() must be a Python list or other iterable" |
|
0 commit comments