mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58:56 +00:00
### What does this PR do? add `lastInsertRowid` (matching SQLite) add `affectedRows` fix `mysql_native_password` deprecated authentication fix AuthSwitch Fixes: https://github.com/oven-sh/bun/issues/22178#issuecomment-3228716080 ### How did you verify your code works? tests --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { SQL } from "bun";
|
|
import { expect, test } from "bun:test";
|
|
import { describeWithContainer } from "harness";
|
|
|
|
describeWithContainer(
|
|
"mysql",
|
|
{
|
|
image: "mysql:8.0.43",
|
|
env: {
|
|
MYSQL_ROOT_PASSWORD: "bun",
|
|
MYSQL_DEFAULT_AUTHENTICATION_PLUGIN: "mysql_native_password",
|
|
},
|
|
args: ["--default-authentication-plugin=mysql_native_password"],
|
|
},
|
|
(port: number) => {
|
|
const options = {
|
|
url: `mysql://root:bun@localhost:${port}`,
|
|
max: 1,
|
|
};
|
|
|
|
test("should be able to connect with mysql_native_password auth plugin", async () => {
|
|
const sql = new SQL({ ...options, password: "bun" });
|
|
const result = await sql`select 1 as x`;
|
|
expect(result).toEqual([{ x: 1 }]);
|
|
await sql.end();
|
|
});
|
|
|
|
test("should be able to switch auth plugin", async () => {
|
|
{
|
|
const sql = new SQL({ ...options, password: "bun" });
|
|
|
|
await sql`CREATE USER caching@'%' IDENTIFIED WITH caching_sha2_password BY 'bunbun';
|
|
GRANT ALL PRIVILEGES ON mysql.* TO caching@'%';
|
|
FLUSH PRIVILEGES;`.simple();
|
|
}
|
|
const sql = new SQL(`mysql://caching:bunbun@localhost:${port}`);
|
|
const result = await sql`select 1 as x`;
|
|
expect(result).toEqual([{ x: 1 }]);
|
|
await sql.end();
|
|
});
|
|
},
|
|
);
|