Skip to content

Commit f19c319

Browse files
refactor(dialects): consolidate identical Postgres/MySQL multi-row INSERT branches
The insert_sql function had byte-for-byte identical code blocks for Postgres (lines 109-116) and MySQL (lines 117-124). Consolidated into a single branch using 'dialect in (POSTGRES, MYSQL)' check, reducing 8 duplicated lines while preserving identical behavior. All 167 tests pass.
1 parent a4be4be commit f19c319

1 file changed

Lines changed: 2 additions & 10 deletions

File tree

src/json2sql/dialects.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,8 @@ def insert_sql(
106106
qcols = [quote_identifier(c, dialect) for c in columns]
107107
col_str = ", ".join(qcols)
108108

109-
if dialect == Dialect.POSTGRES and len(rows) > 1:
110-
# Multi-row INSERT for PostgreSQL
111-
values_parts = []
112-
for row in rows:
113-
val_str = ", ".join(row)
114-
values_parts.append(f" ({val_str})")
115-
values_str = ",\n".join(values_parts)
116-
return f"INSERT INTO {qtable} ({col_str})\nVALUES\n{values_str};"
117-
elif dialect == Dialect.MYSQL and len(rows) > 1:
118-
# Multi-row INSERT for MySQL
109+
if dialect in (Dialect.POSTGRES, Dialect.MYSQL) and len(rows) > 1:
110+
# Multi-row INSERT for PostgreSQL / MySQL
119111
values_parts = []
120112
for row in rows:
121113
val_str = ", ".join(row)

0 commit comments

Comments
 (0)