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

[sql.js]: Fix Column name conversion not working when using sql.js (fix #3643) #3643

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rockmagma02
Copy link

Motivation

Fix #3642

Fix Column name conversion not working when using sql.js

Example Code:

import initSqlJs from "sql.js";
import fs from "node:fs";
import { drizzle } from "drizzle-orm/sql-js";
import { numeric, sqliteTable, text } from "drizzle-orm/sqlite-core";

const testTable = sqliteTable("test", {
	id: numeric().primaryKey().notNull(),
	testSnakeName: text("test_snake_name").notNull(),
});

async function main() {
	const SQL = await initSqlJs();
        // // this a simple sqlite database, which is used to demonstrate this bug
	const dbFile = fs.readFileSync("./test.sqlite");
	const dbOrigin = new SQL.Database(dbFile);
	const db = drizzle(dbOrigin, {
		schema: { testTable },
		logger: true,
	});
	const result = await db.query.testTable.findFirst();
	console.log("result:", result);
	console.log("property:", result?.testSnakeName);
}

await main();

Before Change:

Query: select "id", "test_snake_name" from "test" "testTable" limit ? -- params: [1]
result: { id: 1, test_snake_name: 'test' }
property: undefined

After change

Query: select "id", "test_snake_name" from "test" "testTable" limit ? -- params: [1]
result: { id: 1, testSnakeName: 'test' }
property: test

Although we have excellent drivers for SQLite, such as libsql or better-sqlite3, we require sql.js for specific scenarios, particularly operating on an in-memory database in browser, which is crucial for certain static websites that display or allow users to control dates. I believe that robustly supporting sql.js will benefit Drizzle in adapting to various browser environments.

@rockmagma02 rockmagma02 force-pushed the fix#3642 branch 3 times, most recently from 84182bd to e6ed1fe Compare November 28, 2024 16:48
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

Successfully merging this pull request may close these issues.

[BUG]: Column name conversion not working when using sql.js
1 participant