Skip to content

Support executing sql with template literal#13

Open
miyaji255 wants to merge 2 commits intonuskey8:mainfrom
miyaji255:add-execute-with-template-literal
Open

Support executing sql with template literal#13
miyaji255 wants to merge 2 commits intonuskey8:mainfrom
miyaji255:add-execute-with-template-literal

Conversation

@miyaji255
Copy link

@miyaji255 miyaji255 commented Sep 30, 2025

This pull request introduces support for interpolated string handlers in SQL command execution, improving both performance and developer ergonomics. The main changes include the addition of the ExecuteInterporatedStringHandler type, updates to SqliteConnection to accept this new handler for executing commands, and enhancements to parameter binding. These changes allow SQL queries to be constructed more safely and efficiently using interpolated strings.

Interpolated String Handler Support

  • Added the new ExecuteInterporatedStringHandler ref struct and related types (SqliteParam, SqlitePramKind, SqlitePramPayload) in src/CsSqlite/ExecuteInterporatedStringHandler.cs, enabling efficient and type-safe parameter handling for SQL commands using interpolated strings.

  • Extended SqliteConnection with new overloads for ExecuteNonQuery and ExecuteReader that accept the interpolated string handler, automatically binding parameters based on their types (string, UTF-8 string, integer, double).

Example

var connection = new SqliteConnection(":memory:");
connection.ExecuteNonQuery($"""
INSERT INTO Users
VALUES ({id}, {name}, {age});
""");

@miyaji255 miyaji255 force-pushed the add-execute-with-template-literal branch from 51bc795 to 1e0a392 Compare September 30, 2025 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant