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

Bug: sqlite introspection does not detect autoincrement column when sql contains newlines #235

Closed
tobiasfoerg opened this issue Nov 24, 2022 · 1 comment · Fixed by #236
Assignees
Labels
bug Something isn't working built-in dialect Related to a built-in dialect sqlite Related to sqlite

Comments

@tobiasfoerg
Copy link
Contributor

const autoIncrementCol = createSql[0]?.sql
      ?.split(/[\(\),]/)
      ?.find((it) => it.toLowerCase().includes('autoincrement'))
      ?.split(/\s+/)?.[0]
      ?.replace(/["`]/g, '')

https://github.com/koskimas/kysely/blob/2c49bae555505d347e73ded4cafc0f5dc7279426/src/dialect/sqlite/sqlite-introspector.ts#L68:L72

given the following sql:

CREATE TABLE "users"
(
    "id"         INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,
    "created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "name"       TEXT     NOT NULL
)

the result of find the autoincrement row is: \n "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT
after split on whitespace the first item inside the array is "" instead of ""id""

@igalklebanov
Copy link
Member

Good catch! Can confirm this is happening with given example and is fixed by #236.

@igalklebanov igalklebanov added bug Something isn't working sqlite Related to sqlite built-in dialect Related to a built-in dialect labels Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working built-in dialect Related to a built-in dialect sqlite Related to sqlite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants