lesscode-database 0.0.12__tar.gz → 0.0.13__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.
Potentially problematic release.
This version of lesscode-database might be problematic. Click here for more details.
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/.idea/workspace.xml +87 -7
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/PKG-INFO +1 -1
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/lesscode_database/ds_helper.py +131 -17
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/lesscode_database/orm/orm_exec.py +42 -16
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/pyproject.toml +6 -2
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/uv.lock +2 -2
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/.gitee/ISSUE_TEMPLATE.zh-CN.md +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/.gitignore +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/.idea/.gitignore +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/.idea/inspectionProfiles/profiles_settings.xml +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/.idea/lesscode_database.iml +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/.idea/misc.xml +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/.idea/modules.xml +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/.idea/vcs.xml +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/LICENSE +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/README.en.md +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/README.md +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/demo.py +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/lesscode_database/__init__.py +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/lesscode_database/connect_pool.py +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/lesscode_database/connection_info.py +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/lesscode_database/db_options.py +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/lesscode_database/db_request.py +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/lesscode_database/dynamic_import_package.py +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/lesscode_database/mongo_base_model.py +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/lesscode_database/orm/__init__.py +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/lesscode_database/orm/orm_func.py +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/lesscode_database/orm/orm_model.py +0 -0
- {lesscode_database-0.0.12 → lesscode_database-0.0.13}/lesscode_database/orm/orm_typing.py +0 -0
|
@@ -4,10 +4,8 @@
|
|
|
4
4
|
<option name="autoReloadType" value="SELECTIVE" />
|
|
5
5
|
</component>
|
|
6
6
|
<component name="ChangeListManager">
|
|
7
|
-
<list default="true" id="5ce6a727-6187-4970-b4b5-e0571f06d609" name="Changes" comment="feat(database):
|
|
8
|
-
<change beforePath="$PROJECT_DIR$/
|
|
9
|
-
<change beforePath="$PROJECT_DIR$/lesscode_database/version.py" beforeDir="false" />
|
|
10
|
-
<change beforePath="$PROJECT_DIR$/setup.py" beforeDir="false" />
|
|
7
|
+
<list default="true" id="5ce6a727-6187-4970-b4b5-e0571f06d609" name="Changes" comment="feat(database): 支持 PostgreSQL 和 Oracle 数据库 - 增加了对 PostgreSQL 数据库的支持- 增加了对 Oracle 数据库的支持 - 优化了 ClickHouse 数据库的连接和查询逻辑 - 修复了一些数据库连接和查询的兼容性问题">
|
|
8
|
+
<change beforePath="$PROJECT_DIR$/lesscode_database/ds_helper.py" beforeDir="false" afterPath="$PROJECT_DIR$/lesscode_database/ds_helper.py" afterDir="false" />
|
|
11
9
|
</list>
|
|
12
10
|
<option name="SHOW_DIALOG" value="false" />
|
|
13
11
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
@@ -167,7 +165,7 @@
|
|
|
167
165
|
<workItem from="1745845007941" duration="1773000" />
|
|
168
166
|
<workItem from="1745986151014" duration="194000" />
|
|
169
167
|
<workItem from="1745986369694" duration="6717000" />
|
|
170
|
-
<workItem from="1745993614636" duration="
|
|
168
|
+
<workItem from="1745993614636" duration="10401000" />
|
|
171
169
|
</task>
|
|
172
170
|
<task id="LOCAL-00001" summary="add dm">
|
|
173
171
|
<option name="closed" value="true" />
|
|
@@ -297,7 +295,71 @@
|
|
|
297
295
|
<option name="project" value="LOCAL" />
|
|
298
296
|
<updated>1745992956905</updated>
|
|
299
297
|
</task>
|
|
300
|
-
<
|
|
298
|
+
<task id="LOCAL-00017" summary="feat(database): 增加对 MySQL 数据库的增删查改功能 - 在 DsHelper 类中添加 exec_ 和 async_exec_ 方法,用于执行不同类型的 SQL 查询 - 在 OrmExec 类中实现 all、first、update、delete 和 insert 方法,支持 ORM 方式的数据库操作 - 优化数据库连接池配置,增加 DictCursor 支持">
|
|
299
|
+
<option name="closed" value="true" />
|
|
300
|
+
<created>1745998519478</created>
|
|
301
|
+
<option name="number" value="00017" />
|
|
302
|
+
<option name="presentableId" value="LOCAL-00017" />
|
|
303
|
+
<option name="project" value="LOCAL" />
|
|
304
|
+
<updated>1745998519478</updated>
|
|
305
|
+
</task>
|
|
306
|
+
<task id="LOCAL-00018" summary="feat(orm_exec): 扩展 execute 方法以支持字符串 SQL - 修改 execute 方法,使其可以接受字符串类型的 SQL 查询 - 增加对字符串 SQL 的处理逻辑- 优化了代码格式,调整了缩进和空格">
|
|
307
|
+
<option name="closed" value="true" />
|
|
308
|
+
<created>1745998886644</created>
|
|
309
|
+
<option name="number" value="00018" />
|
|
310
|
+
<option name="presentableId" value="LOCAL-00018" />
|
|
311
|
+
<option name="project" value="LOCAL" />
|
|
312
|
+
<updated>1745998886644</updated>
|
|
313
|
+
</task>
|
|
314
|
+
<task id="LOCAL-00019" summary="refactor(orm): 重构 execute 方法 - 将 sql_object 参数重命名为 statement,提高代码可读性 - 优化 execute 方法的逻辑,支持字符串和 ORM 语句的执行 - 调整代码格式,提高代码整洁度">
|
|
315
|
+
<option name="closed" value="true" />
|
|
316
|
+
<created>1745999022915</created>
|
|
317
|
+
<option name="number" value="00019" />
|
|
318
|
+
<option name="presentableId" value="LOCAL-00019" />
|
|
319
|
+
<option name="project" value="LOCAL" />
|
|
320
|
+
<updated>1745999022915</updated>
|
|
321
|
+
</task>
|
|
322
|
+
<task id="LOCAL-00020" summary="refactor(orm): 修改 sql_type 属性为私有属性 - 将 sql_type 属性从公有改为私有,使用 _sql_type 替代 - 在 ORMExecute 类中更新了相关方法,使用新的私有属性 -此修改提高了代码的封装性,防止外部直接访问和修改 sql_type">
|
|
323
|
+
<option name="closed" value="true" />
|
|
324
|
+
<created>1745999184999</created>
|
|
325
|
+
<option name="number" value="00020" />
|
|
326
|
+
<option name="presentableId" value="LOCAL-00020" />
|
|
327
|
+
<option name="project" value="LOCAL" />
|
|
328
|
+
<updated>1745999184999</updated>
|
|
329
|
+
</task>
|
|
330
|
+
<task id="LOCAL-00021" summary="build(uv.lock): 更新 lesscode-database 包的来源类型- 将 lesscode-database包的来源从 virtual 修改为 editable - 此更改提高了项目构建的灵活性和可维护性">
|
|
331
|
+
<option name="closed" value="true" />
|
|
332
|
+
<created>1745999627273</created>
|
|
333
|
+
<option name="number" value="00021" />
|
|
334
|
+
<option name="presentableId" value="LOCAL-00021" />
|
|
335
|
+
<option name="project" value="LOCAL" />
|
|
336
|
+
<updated>1745999627273</updated>
|
|
337
|
+
</task>
|
|
338
|
+
<task id="LOCAL-00022" summary="feat(database): 支持 SQLite3 数据库 - 在 exec_ 和 async_exec_ 方法中添加了对 SQLite3 数据库的支持 -优化了代码结构,提高了可读性和可维护性 - 保留了原有的功能和逻辑,确保其他数据库类型不受影响">
|
|
339
|
+
<option name="closed" value="true" />
|
|
340
|
+
<created>1746000396808</created>
|
|
341
|
+
<option name="number" value="00022" />
|
|
342
|
+
<option name="presentableId" value="LOCAL-00022" />
|
|
343
|
+
<option name="project" value="LOCAL" />
|
|
344
|
+
<updated>1746000396808</updated>
|
|
345
|
+
</task>
|
|
346
|
+
<task id="LOCAL-00023" summary="feat(database): 添加对 MSSQL 数据库的支持 - 在 exec_ 和 async_exec_ 方法中增加了对 MSSQL 数据库的操作逻辑 -支持 MSSQL 数据库的查询、删除、更新等操作 - 优化了数据库类型不支持时的错误处理">
|
|
347
|
+
<option name="closed" value="true" />
|
|
348
|
+
<created>1746001294684</created>
|
|
349
|
+
<option name="number" value="00023" />
|
|
350
|
+
<option name="presentableId" value="LOCAL-00023" />
|
|
351
|
+
<option name="project" value="LOCAL" />
|
|
352
|
+
<updated>1746001294684</updated>
|
|
353
|
+
</task>
|
|
354
|
+
<task id="LOCAL-00024" summary="feat(database): 支持 PostgreSQL 和 Oracle 数据库 - 增加了对 PostgreSQL 数据库的支持- 增加了对 Oracle 数据库的支持 - 优化了 ClickHouse 数据库的连接和查询逻辑 - 修复了一些数据库连接和查询的兼容性问题">
|
|
355
|
+
<option name="closed" value="true" />
|
|
356
|
+
<created>1746003902878</created>
|
|
357
|
+
<option name="number" value="00024" />
|
|
358
|
+
<option name="presentableId" value="LOCAL-00024" />
|
|
359
|
+
<option name="project" value="LOCAL" />
|
|
360
|
+
<updated>1746003902878</updated>
|
|
361
|
+
</task>
|
|
362
|
+
<option name="localTasksCounter" value="25" />
|
|
301
363
|
<servers />
|
|
302
364
|
</component>
|
|
303
365
|
<component name="TypeScriptGeneratedFilesManager">
|
|
@@ -320,7 +382,25 @@
|
|
|
320
382
|
<MESSAGE value="feat(orm_typing): 为字段类型添加别名属性 - 在 BaseColumnType 类中添加 alias 参数,用于指定字段的别名- 如果未提供别名,则使用字段名称作为默认别名 - 这个改动可以增强 ORM 的灵活性,特别是在处理与数据库字段名称不一致的情况时" />
|
|
321
383
|
<MESSAGE value="refactor(orm): 修改列别名处理逻辑 - 在 BaseColumnType 类中的 alias 方法中添加对别名的赋值操作 - 删除了原本返回 BaseColumnTypeAlias 实例的逻辑" />
|
|
322
384
|
<MESSAGE value="feat(database): 增加对 MySQL 数据库的增删查改功能 - 在 DsHelper 类中添加 exec_ 和 async_exec_ 方法,用于执行不同类型的 SQL 查询 - 在 OrmExec 类中实现 all、first、update、delete 和 insert 方法,支持 ORM 方式的数据库操作 - 优化数据库连接池配置,增加 DictCursor 支持" />
|
|
323
|
-
<
|
|
385
|
+
<MESSAGE value="feat(orm_exec): 扩展 execute 方法以支持字符串 SQL - 修改 execute 方法,使其可以接受字符串类型的 SQL 查询 - 增加对字符串 SQL 的处理逻辑- 优化了代码格式,调整了缩进和空格" />
|
|
386
|
+
<MESSAGE value="refactor(orm): 重构 execute 方法 - 将 sql_object 参数重命名为 statement,提高代码可读性 - 优化 execute 方法的逻辑,支持字符串和 ORM 语句的执行 - 调整代码格式,提高代码整洁度" />
|
|
387
|
+
<MESSAGE value="refactor(orm): 修改 sql_type 属性为私有属性 - 将 sql_type 属性从公有改为私有,使用 _sql_type 替代 - 在 ORMExecute 类中更新了相关方法,使用新的私有属性 -此修改提高了代码的封装性,防止外部直接访问和修改 sql_type" />
|
|
388
|
+
<MESSAGE value="build(uv.lock): 更新 lesscode-database 包的来源类型- 将 lesscode-database包的来源从 virtual 修改为 editable - 此更改提高了项目构建的灵活性和可维护性" />
|
|
389
|
+
<MESSAGE value="feat(database): 支持 SQLite3 数据库 - 在 exec_ 和 async_exec_ 方法中添加了对 SQLite3 数据库的支持 -优化了代码结构,提高了可读性和可维护性 - 保留了原有的功能和逻辑,确保其他数据库类型不受影响" />
|
|
390
|
+
<MESSAGE value="feat(database): 添加对 MSSQL 数据库的支持 - 在 exec_ 和 async_exec_ 方法中增加了对 MSSQL 数据库的操作逻辑 -支持 MSSQL 数据库的查询、删除、更新等操作 - 优化了数据库类型不支持时的错误处理" />
|
|
391
|
+
<MESSAGE value="feat(database): 支持 PostgreSQL 和 Oracle 数据库 - 增加了对 PostgreSQL 数据库的支持- 增加了对 Oracle 数据库的支持 - 优化了 ClickHouse 数据库的连接和查询逻辑 - 修复了一些数据库连接和查询的兼容性问题" />
|
|
392
|
+
<option name="LAST_COMMIT_MESSAGE" value="feat(database): 支持 PostgreSQL 和 Oracle 数据库 - 增加了对 PostgreSQL 数据库的支持- 增加了对 Oracle 数据库的支持 - 优化了 ClickHouse 数据库的连接和查询逻辑 - 修复了一些数据库连接和查询的兼容性问题" />
|
|
393
|
+
</component>
|
|
394
|
+
<component name="XDebuggerManager">
|
|
395
|
+
<breakpoint-manager>
|
|
396
|
+
<breakpoints>
|
|
397
|
+
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
|
|
398
|
+
<url>file://$PROJECT_DIR$/lesscode_database/ds_helper.py</url>
|
|
399
|
+
<line>288</line>
|
|
400
|
+
<option name="timeStamp" value="1" />
|
|
401
|
+
</line-breakpoint>
|
|
402
|
+
</breakpoints>
|
|
403
|
+
</breakpoint-manager>
|
|
324
404
|
</component>
|
|
325
405
|
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
|
326
406
|
<SUITE FILE_PATH="coverage/lesscode_database$t.coverage" NAME="t Coverage Results" MODIFIED="1743923878274" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
|
@@ -136,11 +136,13 @@ class DsHelper:
|
|
|
136
136
|
raise e
|
|
137
137
|
return res
|
|
138
138
|
|
|
139
|
-
|
|
140
|
-
def exec_(self,sql_type:str,sql):
|
|
139
|
+
def exec_(self, sql_type: str, sql):
|
|
141
140
|
if sql_type not in ["all", "first", "delete", "update", "insert"]:
|
|
142
141
|
raise Exception(f"sql_type must be all,first,delete,update,insert")
|
|
143
|
-
|
|
142
|
+
connect_params = self.connect_info.params or {}
|
|
143
|
+
creator_type = connect_params.get("creator_type") or "clickhouse_driver"
|
|
144
|
+
if self.connect_info.db_type in ["mysql", "doris", "ocean_base", "tidb", "sqlite3", "dm"] or (
|
|
145
|
+
self.connect_info.db_type == "clickhouse" and creator_type == "clickhouse_driver"):
|
|
144
146
|
if sql_type == "all":
|
|
145
147
|
with self.pool.dedicated_connection() as conn:
|
|
146
148
|
conn.ping(reconnect=True)
|
|
@@ -171,23 +173,92 @@ class DsHelper:
|
|
|
171
173
|
with self.pool.dedicated_connection() as conn:
|
|
172
174
|
conn.ping(reconnect=True)
|
|
173
175
|
with conn.cursor() as cursor:
|
|
174
|
-
rs= cursor.execute(sql)
|
|
176
|
+
rs = cursor.execute(sql)
|
|
175
177
|
return rs
|
|
176
178
|
|
|
177
179
|
|
|
178
|
-
elif self.connect_info.db_type
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
180
|
+
elif self.connect_info.db_type in ["mssql", "oracle"]:
|
|
181
|
+
if sql_type == "all":
|
|
182
|
+
cursor = self.pool.cursor()
|
|
183
|
+
cursor.execute(sql)
|
|
184
|
+
rs = cursor.fetchall()
|
|
185
|
+
return rs
|
|
186
|
+
elif sql_type == "first":
|
|
187
|
+
cursor = self.pool.cursor()
|
|
188
|
+
cursor.execute(sql)
|
|
189
|
+
rs = cursor.fetchone()
|
|
190
|
+
return rs
|
|
191
|
+
elif sql_type == "delete":
|
|
192
|
+
cursor = self.pool.cursor()
|
|
193
|
+
rs = cursor.execute(sql)
|
|
194
|
+
return rs
|
|
195
|
+
elif sql_type == "update":
|
|
196
|
+
cursor = self.pool.cursor()
|
|
197
|
+
rs = cursor.execute(sql)
|
|
198
|
+
return rs
|
|
199
|
+
else:
|
|
200
|
+
cursor = self.pool.cursor()
|
|
201
|
+
rs = cursor.execute(sql)
|
|
202
|
+
return rs
|
|
203
|
+
elif self.connect_info.db_type in ["postgresql"]:
|
|
204
|
+
if sql_type == "all":
|
|
205
|
+
with self.pool.connection() as conn:
|
|
206
|
+
with conn.cursor() as cursor:
|
|
207
|
+
cursor.execute(sql)
|
|
208
|
+
rs = cursor.fetchall()
|
|
209
|
+
return rs
|
|
210
|
+
elif sql_type == "first":
|
|
211
|
+
with self.pool.connection() as conn:
|
|
212
|
+
with conn.cursor() as cursor:
|
|
213
|
+
cursor.execute(sql)
|
|
214
|
+
rs = cursor.fetchone()
|
|
215
|
+
return rs
|
|
216
|
+
elif sql_type == "delete":
|
|
217
|
+
with self.pool.connection() as conn:
|
|
218
|
+
with conn.cursor() as cursor:
|
|
219
|
+
rs = cursor.execute(sql)
|
|
220
|
+
return rs
|
|
221
|
+
elif sql_type == "update":
|
|
222
|
+
with self.pool.connection() as conn:
|
|
223
|
+
with conn.cursor() as cursor:
|
|
224
|
+
rs = cursor.execute(sql)
|
|
225
|
+
return rs
|
|
226
|
+
else:
|
|
227
|
+
with self.pool.connection() as conn:
|
|
228
|
+
with conn.cursor() as cursor:
|
|
229
|
+
rs = cursor.execute(sql)
|
|
230
|
+
return rs
|
|
231
|
+
elif self.connect_info.db_type == "clickhouse" and creator_type == "clickhouse_connect":
|
|
232
|
+
if sql_type == "all":
|
|
233
|
+
result = self.pool.query(sql).result_rows
|
|
234
|
+
columns = result.column_names
|
|
235
|
+
rows = result.result_rows
|
|
236
|
+
return [dict(zip(columns, row)) for row in rows]
|
|
237
|
+
elif sql_type == "first":
|
|
238
|
+
if "limit" not in sql:
|
|
239
|
+
sql += " limit 1"
|
|
240
|
+
result = self.pool.query(sql).result_rows
|
|
241
|
+
columns = result.column_names
|
|
242
|
+
rows = result.result_rows
|
|
243
|
+
return [dict(zip(columns, row)) for row in rows]
|
|
244
|
+
elif sql_type == "delete":
|
|
245
|
+
rs = self.pool.command(sql)
|
|
246
|
+
return rs
|
|
247
|
+
elif sql_type == "update":
|
|
248
|
+
rs = self.pool.command(sql)
|
|
249
|
+
return rs
|
|
250
|
+
else:
|
|
251
|
+
rs = self.pool.command(sql)
|
|
252
|
+
return rs
|
|
184
253
|
else:
|
|
185
|
-
|
|
254
|
+
raise Exception(f"暂不支持数据库类型:{self.connect_info.db_type}")
|
|
186
255
|
|
|
187
|
-
async def async_exec_(self,sql_type:str,sql):
|
|
256
|
+
async def async_exec_(self, sql_type: str, sql):
|
|
188
257
|
if sql_type not in ["all", "first", "delete", "update", "insert"]:
|
|
189
258
|
raise Exception(f"sql_type must be all,first,delete,update,insert")
|
|
190
|
-
|
|
259
|
+
connect_params = self.connect_info.params or {}
|
|
260
|
+
creator_type = connect_params.get("creator_type") or "clickhouse_driver"
|
|
261
|
+
if self.connect_info.db_type in ["mysql", "doris", "ocean_base", "tidb", "postgresql"]:
|
|
191
262
|
if sql_type == "all":
|
|
192
263
|
async with self.pool.acquire() as conn:
|
|
193
264
|
async with conn.cursor() as cursor:
|
|
@@ -213,9 +284,52 @@ class DsHelper:
|
|
|
213
284
|
else:
|
|
214
285
|
async with self.pool.acquire() as conn:
|
|
215
286
|
async with conn.cursor() as cursor:
|
|
216
|
-
rs= await cursor.execute(sql)
|
|
287
|
+
rs = await cursor.execute(sql)
|
|
217
288
|
return rs
|
|
218
|
-
elif self.connect_info.db_type
|
|
219
|
-
|
|
289
|
+
elif self.connect_info.db_type in ["sqlite3"]:
|
|
290
|
+
if sql_type == "all":
|
|
291
|
+
cur = await self.pool.cursor()
|
|
292
|
+
await cur.execute(sql)
|
|
293
|
+
rs = await cur.fetchall()
|
|
294
|
+
return rs
|
|
295
|
+
elif sql_type == "first":
|
|
296
|
+
cur = await self.pool.cursor()
|
|
297
|
+
await cur.execute(sql)
|
|
298
|
+
rs = await cur.fetchone()
|
|
299
|
+
return rs
|
|
300
|
+
elif sql_type == "delete":
|
|
301
|
+
cur = await self.pool.cursor()
|
|
302
|
+
rs = await cur.execute(sql)
|
|
303
|
+
return rs
|
|
304
|
+
elif sql_type == "update":
|
|
305
|
+
cur = await self.pool.cursor()
|
|
306
|
+
rs = await cur.execute(sql)
|
|
307
|
+
return rs
|
|
308
|
+
else:
|
|
309
|
+
cur = await self.pool.cursor()
|
|
310
|
+
rs = await cur.execute(sql)
|
|
311
|
+
return rs
|
|
312
|
+
elif self.connect_info.db_type == "clickhouse" and creator_type == "clickhouse_connect":
|
|
313
|
+
if sql_type == "all":
|
|
314
|
+
result = await self.pool.query(sql).result_rows
|
|
315
|
+
columns = result.column_names
|
|
316
|
+
rows = result.result_rows
|
|
317
|
+
return [dict(zip(columns, row)) for row in rows]
|
|
318
|
+
elif sql_type == "first":
|
|
319
|
+
if "limit" not in sql:
|
|
320
|
+
sql += " limit 1"
|
|
321
|
+
result = await self.pool.query(sql).result_rows
|
|
322
|
+
columns = result.column_names
|
|
323
|
+
rows = result.result_rows
|
|
324
|
+
return [dict(zip(columns, row)) for row in rows]
|
|
325
|
+
elif sql_type == "delete":
|
|
326
|
+
rs = await self.pool.command(sql)
|
|
327
|
+
return rs
|
|
328
|
+
elif sql_type == "update":
|
|
329
|
+
rs = await self.pool.command(sql)
|
|
330
|
+
return rs
|
|
331
|
+
else:
|
|
332
|
+
rs = await self.pool.command(sql)
|
|
333
|
+
return rs
|
|
220
334
|
else:
|
|
221
|
-
|
|
335
|
+
raise Exception(f"暂不支持数据库类型:{self.connect_info.db_type}")
|
|
@@ -246,40 +246,66 @@ class Exec:
|
|
|
246
246
|
self.__connect_name__ = connect_name or self.__connect_name__
|
|
247
247
|
self._sql = ""
|
|
248
248
|
self._result = None
|
|
249
|
-
self.
|
|
249
|
+
self._sql_type = ""
|
|
250
250
|
|
|
251
|
-
def execute(self,
|
|
252
|
-
if not self.__connect_name__:
|
|
253
|
-
self.__connect_name__ =
|
|
254
|
-
|
|
255
|
-
|
|
251
|
+
def execute(self, statement: Union[Select, Update, Delete, Insert, str]):
|
|
252
|
+
if not self.__connect_name__ and not isinstance(statement, str):
|
|
253
|
+
self.__connect_name__ = statement._connect_name
|
|
254
|
+
if isinstance(statement, str):
|
|
255
|
+
self._sql = statement
|
|
256
256
|
return self
|
|
257
257
|
else:
|
|
258
|
+
self._sql = statement._sql()
|
|
258
259
|
return self
|
|
259
260
|
|
|
260
261
|
def all(self):
|
|
261
|
-
self.
|
|
262
|
-
self._result = DsHelper(self.__connect_name__).exec_(self.
|
|
262
|
+
self._sql_type = "all"
|
|
263
|
+
self._result = DsHelper(self.__connect_name__).exec_(self._sql_type, self._sql)
|
|
264
|
+
return self._result
|
|
265
|
+
|
|
266
|
+
async def async_all(self):
|
|
267
|
+
self._sql_type = "all"
|
|
268
|
+
self._result = await DsHelper(self.__connect_name__).async_exec_(self._sql_type, self._sql)
|
|
263
269
|
return self._result
|
|
264
270
|
|
|
265
271
|
def first(self):
|
|
266
|
-
self.
|
|
267
|
-
self._result = DsHelper(self.__connect_name__).exec_(self.
|
|
272
|
+
self._sql_type = "first"
|
|
273
|
+
self._result = DsHelper(self.__connect_name__).exec_(self._sql_type, self._sql)
|
|
274
|
+
return self._result
|
|
275
|
+
|
|
276
|
+
async def async_first(self):
|
|
277
|
+
self._sql_type = "first"
|
|
278
|
+
self._result = await DsHelper(self.__connect_name__).async_exec_(self._sql_type, self._sql)
|
|
268
279
|
return self._result
|
|
269
280
|
|
|
270
281
|
def update(self):
|
|
271
|
-
self.
|
|
272
|
-
self._result = DsHelper(self.__connect_name__).exec_(self.
|
|
282
|
+
self._sql_type = "update"
|
|
283
|
+
self._result = DsHelper(self.__connect_name__).exec_(self._sql_type, self._sql)
|
|
284
|
+
return self._result
|
|
285
|
+
|
|
286
|
+
async def async_update(self):
|
|
287
|
+
self._sql_type = "update"
|
|
288
|
+
self._result = await DsHelper(self.__connect_name__).async_exec_(self._sql_type, self._sql)
|
|
273
289
|
return self._result
|
|
274
290
|
|
|
275
291
|
def delete(self):
|
|
276
|
-
self.
|
|
277
|
-
self._result = DsHelper(self.__connect_name__).exec_(self.
|
|
292
|
+
self._sql_type = "delete"
|
|
293
|
+
self._result = DsHelper(self.__connect_name__).exec_(self._sql_type, self._sql)
|
|
294
|
+
return self._result
|
|
295
|
+
|
|
296
|
+
async def async_delete(self):
|
|
297
|
+
self._sql_type = "delete"
|
|
298
|
+
self._result = await DsHelper(self.__connect_name__).async_exec_(self._sql_type, self._sql)
|
|
278
299
|
return self._result
|
|
279
300
|
|
|
280
301
|
def insert(self):
|
|
281
|
-
self.
|
|
282
|
-
self._result = DsHelper(self.__connect_name__).exec_(self.
|
|
302
|
+
self._sql_type = "insert"
|
|
303
|
+
self._result = DsHelper(self.__connect_name__).exec_(self._sql_type, self._sql)
|
|
304
|
+
return self._result
|
|
305
|
+
|
|
306
|
+
async def async_insert(self):
|
|
307
|
+
self._sql_type = "insert"
|
|
308
|
+
self._result = await DsHelper(self.__connect_name__).async_exec_(self._sql_type, self._sql)
|
|
283
309
|
return self._result
|
|
284
310
|
|
|
285
311
|
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "lesscode-database"
|
|
7
|
-
version = "0.0.
|
|
7
|
+
version = "0.0.13"
|
|
8
8
|
description = "lesscode_database是数据库连接工具包"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.7"
|
|
@@ -22,4 +22,8 @@ dependencies = []
|
|
|
22
22
|
|
|
23
23
|
[tool.setuptools]
|
|
24
24
|
packages = ["lesscode_database"]
|
|
25
|
-
package-dir = {"" = "."}
|
|
25
|
+
package-dir = {"" = "."}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# 打包命令:uv build
|
|
29
|
+
# 发布命令: uvx twine upload dist/*
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{lesscode_database-0.0.12 → lesscode_database-0.0.13}/.idea/inspectionProfiles/profiles_settings.xml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{lesscode_database-0.0.12 → lesscode_database-0.0.13}/lesscode_database/dynamic_import_package.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|