Skip to content

Accept an object as first parameter in execute et al. #1629

@PhilippSalvisberg

Description

@PhilippSalvisberg

The popular npm module sql-template-tag supports oracledb in the latest version 5.2.0. So we can write code like this:

const query = sql`select * from emp where deptno = ${deptno} order by sal desc`;
const result = session.execute(query.statement, query.values);

However, I'd like to make the code more compact. Similar to MySQL and PostgreSQL. Something like this:

const result = session.execute(sql`select * from emp where deptno = ${deptno} order by sal desc`);

To make it work, the execute function and related functions need to accept a JSON object as first parameter. Similar to the implementation in MySQL for query. The object contains a statement field with positional bind parameters for oracledb. The bind values are provided in the values field.

IMO this would improve the usability in a backward-compatible way. Making the use of bind parameters as simple as in MySQL and PostgreSQL.

Using the sql-template-tag makes template literals containing large SQL statements easy to read, even with positional bind parameters. It's similar to static SQL in PL/SQL. This makes the use of named bind parameters in a lot of cases unnecessary.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions