Description
When using waddler/neon-serverless, SQL queries built with append() fail with a syntax error. The toSQL() method returns the correct SQL, but the query sent to the database only contains the initial SQL fragment.
Reproduction
import { waddler } from "waddler/neon-serverless";
const sql = waddler({ connection: "postgresql://...@...-pooler.neon.tech/..." });
// Works: direct template literal
await sql`WITH cte AS (SELECT 1 as num) SELECT * FROM cte`; // ✅ OK
// Fails: using append()
const query = sql`WITH`;
query.append(sql` cte AS (SELECT 1 as num)`);
query.append(sql` SELECT * FROM cte`);
console.log(query.toSQL());
// → { sql: "WITH cte AS (SELECT 1 as num) SELECT * FROM cte", params: [] } ✅ Correct
console.log((query as any).queryConfig.text);
// → "WITH" ❌ Still the initial value!
await query;
// Error: syntax error at end of input (position: 5)
Root Cause
In NeonServerlessSQLTemplate, queryConfig.text is set once in the constructor and never updated after append() calls:
// Constructor - sets queryConfig.text once
constructor(sqlWrapper, client, dialect, configOptions, options) {
// ...
const query = this.sqlWrapper.getQuery(this.dialect).sql;
this.queryConfig = {
rowMode: "array",
text: query, // ← Fixed at construction time
types: pgTypeConfig,
};
}
// execute() - uses stale queryConfig
async execute() {
const { sql: query, params } = this.sqlWrapper.getQuery(this.dialect);
// query is correct here, but queryConfig.text is stale
const queryResult = await this.client.query(this.queryConfig, params);
// ↑ Sends the old SQL text
}
Proposed Fix
The fix is minimal - just update queryConfig.text and rawQueryConfig.text in execute() before sending the query:
async execute() {
const { sql: query, params } = this.sqlWrapper.getQuery(this.dialect);
this.queryConfig.text = query; // ← Add this
this.rawQueryConfig.text = query; // ← Add this
// ... rest unchanged
}
Happy to open a PR if this approach looks good.
Environment
- waddler version: 0.1.1
- Driver: waddler/neon-serverless
- Database: Neon PostgreSQL (pooler connection)
Description
When using
waddler/neon-serverless, SQL queries built withappend()fail with a syntax error. ThetoSQL()method returns the correct SQL, but the query sent to the database only contains the initial SQL fragment.Reproduction
Root Cause
In
NeonServerlessSQLTemplate,queryConfig.textis set once in the constructor and never updated afterappend()calls:Proposed Fix
The fix is minimal - just update
queryConfig.textandrawQueryConfig.textinexecute()before sending the query:Happy to open a PR if this approach looks good.
Environment