Skip to content

Conversation

@immz4
Copy link
Contributor

@immz4 immz4 commented Aug 15, 2025

Add better-sqlite3 to the DataSource type check

Example code:

import { SqlDatabase } from "langchain/sql_db";
import { DataSource } from "typeorm";

const datasource = new DataSource({
  type: "better-sqlite3",
  database: "test.db",
  readonly: true,
});

const db = await SqlDatabase.fromDataSourceParams({
  appDataSource: datasource,
});

console.log(await db.getTableInfo())

Execution before fix:

❯ pnpm exec tsx index-mini.ts
file:///home/lemon/Documents/text-to-sql-mcp/node_modules/.pnpm/langchain@0.3.30_@langchain+core@0.3.70_@opentelemetry+api@1.9.0_openai@5.12.2_zod@4.0.17___@_oks7tym3ksu5msad6f4d7govii/node_modules/langchain/dist/util/sql_utils.js:140
    throw new Error("Database type not implemented yet");
          ^

Error: Database type not implemented yet
    at getTableAndColumnsName (file:///home/lemon/Documents/text-to-sql-mcp/node_modules/.pnpm/langchain@0.3.30_@langchain+core@0.3.70_@opentelemetry+api@1.9.0_openai@5.12.2_zod@4.0.17___@_oks7tym3ksu5msad6f4d7govii/node_modules/langchain/dist/util/sql_utils.js:140:11)
    at SqlDatabase.fromDataSourceParams (/home/lemon/Documents/text-to-sql-mcp/node_modules/.pnpm/langchain@0.3.30_@langchain+core@0.3.70_@opentelemetry+api@1.9.0_openai@5.12.2_zod@4.0.17___@_oks7tym3ksu5msad6f4d7govii/node_modules/langchain/dist/sql_db.js:86:39)
    at async <anonymous> (/home/lemon/Documents/text-to-sql-mcp/index-mini.ts:10:12)

Node.js v24.5.0

Execution after fix:

❯ pnpm exec tsx index-mini.ts
CREATE TABLE contacts (
id INTEGER , first_name TEXT NOT NULL, last_name TEXT NOT NULL, city TEXT , created_at DATETIME ) 
SELECT * FROM "contacts" LIMIT 3;
 id first_name last_name city created_at
 1 John Smith New York 2024-01-15 09:30:00
 2 Sarah Johnson Los Angeles 2024-01-20 14:22:15
 3 Michael Brown Chicago 2024-02-03 11:45:30
CREATE TABLE cases (
id INTEGER , topic TEXT NOT NULL, created_at DATETIME ) 
SELECT * FROM "cases" LIMIT 3;
 id topic created_at
 1 Website Development 2024-01-18 10:15:30
 2 Mobile App Bug Fix 2024-01-25 14:30:45
 3 Database Migration 2024-02-08 09:45:20

@vercel
Copy link

vercel bot commented Aug 15, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
langchainjs-docs Ready Ready Preview Aug 15, 2025 8:13pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
langchainjs-api-refs Ignored Ignored Aug 15, 2025 8:13pm

@hntrl
Copy link
Member

hntrl commented Aug 15, 2025

Thanks for the PR @immz4!

Just as a heads up, we're reassessing sql utils for the langchain package as apart of v1. We'll wave this through since its pretty minimal, but these primitives you're touching are subject to heavy changes.

@hntrl hntrl merged commit 71c9755 into langchain-ai:main Aug 15, 2025
29 of 30 checks passed
hntrl added a commit that referenced this pull request Oct 14, 2025
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.

2 participants