-
-
Save twiddler/8f98b48ec61c75eaa5422249c1edebc9 to your computer and use it in GitHub Desktop.
Unexpected result with kysely-planetscale
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PLANETSCALE_URL='mysql://foo:pscale_pw_bar@aws.connect.psdb.cloud/baz?ssl={"rejectUnauthorized":true}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Kysely, MysqlDialect } from "kysely"; | |
import { PlanetScaleDialect } from "kysely-planetscale"; | |
import { createPool } from "mysql2"; | |
import { strict as assert } from "node:assert"; | |
import { describe, test } from "node:test"; | |
import { fetch } from "undici"; | |
describe("mysql", function () { | |
const db = new Kysely({ | |
dialect: new MysqlDialect({ | |
pool: createPool({ | |
database: "mysql", | |
host: "localhost", | |
user: "root", | |
password: "", | |
}), | |
}), | |
}); | |
test("one row", async function () { | |
const q = await db | |
.selectFrom([ | |
db.selectNoFrom((eb) => eb.val(0).as("num_column")).as("foo"), | |
]) | |
.selectAll() | |
.execute(); | |
assert.deepStrictEqual(q, [{ num_column: 0 }]); // ✅ | |
}); | |
test("two rows", async function () { | |
const q = await db | |
.selectFrom([ | |
db | |
.selectNoFrom((eb) => eb.val(0).as("num_column")) | |
.unionAll(db.selectNoFrom((eb) => eb.val(0).as("num_column"))) | |
.as("foo"), | |
]) | |
.selectAll() | |
.execute(); | |
assert.deepStrictEqual(q, [{ num_column: 0 }, { num_column: 0 }]); // ✅ | |
}); | |
}); | |
describe("planetscale", function () { | |
const db = new Kysely({ | |
dialect: new PlanetScaleDialect({ | |
url: process.env.PLANETSCALE_URL, | |
fetch, | |
}), | |
}); | |
test("one row", async function () { | |
const q = await db | |
.selectFrom([ | |
db.selectNoFrom((eb) => eb.val(0).as("num_column")).as("foo"), | |
]) | |
.selectAll() | |
.execute(); | |
assert.deepStrictEqual(q, [{ num_column: 0 }]); // ✅ | |
}); | |
test("two rows", async function () { | |
const q = await db | |
.selectFrom([ | |
db | |
.selectNoFrom((eb) => eb.val(0).as("num_column")) | |
.unionAll(db.selectNoFrom((eb) => eb.val(0).as("num_column"))) | |
.as("foo"), | |
]) | |
.selectAll() | |
.execute(); | |
assert.deepStrictEqual(q, [{ num_column: 0 }, { num_column: 0 }]); // ❌ actual: [ { num_column: '0' }, { num_column: '0' } ] | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"private": true, | |
"type": "module", | |
"scripts": { | |
"test": "tsx --env-file=.env --test \"./*.test.mts\"" | |
}, | |
"devDependencies": { | |
"@types/node": "^20.12.7", | |
"tsx": "^4.7.3", | |
"typescript": "^5.4.5" | |
}, | |
"dependencies": { | |
"@planetscale/database": "^1.17.0", | |
"kysely": "^0.27.3", | |
"kysely-planetscale": "^1.4.0", | |
"mysql2": "^3.9.7", | |
"undici": "^6.14.1" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"$schema": "https://json.schemastore.org/tsconfig", | |
"compilerOptions": { | |
"module": "NodeNext", | |
"moduleResolution": "NodeNext", | |
"strict": true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment