Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning() returns different result on mssql and sqlite3 #5378

Open
Simon-HL opened this issue Nov 11, 2022 · 0 comments
Open

Returning() returns different result on mssql and sqlite3 #5378

Simon-HL opened this issue Nov 11, 2022 · 0 comments

Comments

@Simon-HL
Copy link

Environment

Knex version: 2.3.0
Sqlite3 version: 5.1.2
Database + version: Microsoft SQL Server

For MSSql tag @smorey2

Bug

tldr; Unit tests returns an array of objects from sqlite, but from mssql it returns an array of values

After updating to v2.3.0, a unit test for insert that used returning() started failing. The changelog reports that v2.3 introduced support for returning() for sqlite3. I tried editing my code to follow the documentation for returning(). That fixed the unit tests but I now receive the following error in my deployed environment with mssql:

Error: Undefined binding(s) detected for keys [0] when compiling RAW query: ?

Below is a code snippet showing my code before and after v2.3 and my attempt to fix it. Am I doing something wrong or this a bug?

Worked on v2.2.0

        const [ id ]: number[] = await db
            .insert(entity)
            .into(this.table)
            .returning('MyId')

       // v2.2.0
       // Returns: id: 123 from sqlite
       // Returns: id: 123 from mssql

       // v2.3.0
       // Returns: id: { MyId: 123 } from sqlite
       // Returns: id: 123 from mssql

Works on v2.3.0 for sqlite3 but fails on mssql

        const [{ MyId }]: { MyId: number }[] = await db
            .returning('MyId')
            .insert(entity)
            .into(this.table)

         // Returns: id: 123 on sqlite3
         // Returns: undefined on mssql
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

No branches or pull requests

1 participant