reydb 1.1.41__py3-none-any.whl → 1.1.42__py3-none-any.whl

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.
reydb/rdb.py CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
 
12
12
  from typing import Any, Literal, overload
13
- from collections.abc import Iterable, Generator
13
+ from collections.abc import Iterable, Generator, Container
14
14
  from enum import EnumType
15
15
  from urllib.parse import quote as urllib_quote
16
16
  from pymysql.constants.CLIENT import MULTI_STATEMENTS
@@ -793,7 +793,7 @@ class Database(DatabaseBase):
793
793
  self,
794
794
  path: str | tuple[str, str],
795
795
  data: TableData,
796
- duplicate: Literal['ignore', 'update'] | None = None,
796
+ duplicate: Literal['ignore', 'update'] | Container[str] | None = None,
797
797
  report: bool | None = None,
798
798
  **kwdata: Any
799
799
  ) -> Result:
@@ -808,8 +808,9 @@ class Database(DatabaseBase):
808
808
  data : Insert data.
809
809
  duplicate : Handle method when constraint error.
810
810
  - `None`: Not handled.
811
- - `ignore`, Use `UPDATE IGNORE INTO`: clause.
812
- - `update`, Use `ON DUPLICATE KEY UPDATE`: clause.
811
+ - `ignore`: Use `UPDATE IGNORE INTO` clause.
812
+ - `update`: Use `ON DUPLICATE KEY UPDATE` clause and update all fields.
813
+ - `Container[str]`: Use `ON DUPLICATE KEY UPDATE` clause and update this fields.
813
814
  report : Whether report SQL execute information.
814
815
  - `None`, Use attribute `report_execute_info`: of object `ROption`.
815
816
  - `int`: Use this value.
@@ -901,6 +902,13 @@ class Database(DatabaseBase):
901
902
  ## Join sql part.
902
903
  match duplicate:
903
904
 
905
+ ### Not handle.
906
+ case None:
907
+ sql = (
908
+ f'INSERT INTO `{database}`.`{table}`({sql_fields})\n'
909
+ f'VALUES({sql_values})'
910
+ )
911
+
904
912
  ### Ignore.
905
913
  case 'ignore':
906
914
  sql = (
@@ -909,8 +917,20 @@ class Database(DatabaseBase):
909
917
  )
910
918
 
911
919
  ### Update.
912
- case 'update':
913
- update_content = ',\n '.join([f'`{field}` = VALUES(`{field}`)' for field in sql_fields_list])
920
+ case _:
921
+ sql_fields_list_update = sql_fields_list
922
+ if duplicate != 'update':
923
+ sql_fields_list_update = [
924
+ field
925
+ for field in sql_fields_list
926
+ if field in duplicate
927
+ ]
928
+ update_content = ',\n '.join(
929
+ [
930
+ f'`{field}` = VALUES(`{field}`)'
931
+ for field in sql_fields_list_update
932
+ ]
933
+ )
914
934
  sql = (
915
935
  f'INSERT INTO `{database}`.`{table}`({sql_fields})\n'
916
936
  f'VALUES({sql_values})\n'
@@ -918,13 +938,6 @@ class Database(DatabaseBase):
918
938
  f' {update_content}'
919
939
  )
920
940
 
921
- ### Not handle.
922
- case _:
923
- sql = (
924
- f'INSERT INTO `{database}`.`{table}`({sql_fields})\n'
925
- f'VALUES({sql_values})'
926
- )
927
-
928
941
  # Execute SQL.
929
942
  result = self.execute(sql, data, report, **kwdata_replace)
930
943
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reydb
3
- Version: 1.1.41
3
+ Version: 1.1.42
4
4
  Summary: Database method set.
5
5
  Project-URL: homepage, https://github.com/reyxbo/reydb/
6
6
  Author-email: Rey <reyxbo@163.com>
@@ -4,13 +4,13 @@ reydb/rbase.py,sha256=HYoFasGBAhXUUHNFP1doGnHBW3-xkgRc32O9KppGSak,4824
4
4
  reydb/rbuild.py,sha256=iXJ76BNlUflJfMAAEbPuQLyVePyye8aDq7MaXD16Ktw,32419
5
5
  reydb/rconfig.py,sha256=1uQG-khhkupKgzC51nYku3P__-qdaSXZB13GdDyKy00,12312
6
6
  reydb/rconn.py,sha256=YWscFMjBph9ttPXjzTTpaziTd7v7vnE0b7E4mVpJ6oc,6163
7
- reydb/rdb.py,sha256=oDGETlNQqXe2_YzSuX4WE1xhiIlVCGidLevj0fi5GXY,54229
7
+ reydb/rdb.py,sha256=3Kr8U6YoxExfUhiaSXUzvfwhOyAdcNZJYicr0Bb8zX4,54791
8
8
  reydb/rerror.py,sha256=lirCR6yv1-9JsC6ZIKCkS0ezcNojAOAbJpup2xtsyx0,9968
9
9
  reydb/rexec.py,sha256=dGdRkG1XR0Z66T0r4nPCSdQzSRWc_Q3t6TPSSrDTIxY,9042
10
10
  reydb/rfile.py,sha256=JoXI_YgR5TDR7kh06eU0TngEOkSW8DmcZ4SDjTl22Wk,15255
11
11
  reydb/rinfo.py,sha256=KXTkcpTGAD3p9RVKKcnmc_FjJtiKRPk-K5ZepPOnphQ,15253
12
12
  reydb/rparam.py,sha256=6cnSjNlX54iPS1uxMQdpazPM5XL4J87vVgfL6CIYG3U,7031
13
- reydb-1.1.41.dist-info/METADATA,sha256=sDxvROWfJSEVtOt1ktDArlAxj8J8-RsLy2G53y-laLQ,1550
14
- reydb-1.1.41.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
15
- reydb-1.1.41.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
16
- reydb-1.1.41.dist-info/RECORD,,
13
+ reydb-1.1.42.dist-info/METADATA,sha256=uAVh_Vj1Vs3U2P022pBnZRvrwzPzxAyu0X_ULJOEKA0,1550
14
+ reydb-1.1.42.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
15
+ reydb-1.1.42.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
16
+ reydb-1.1.42.dist-info/RECORD,,
File without changes