Registry / database / bunqldb

bunqldb

JSON →
library0.4.2jsnpmunverified

bunqldb 0.4.2는 Bun 네이티브 SQL 클라이언트(Bun.sql)를 기반으로 한 MySQL/PostgreSQL 호환 데이터베이스 모듈입니다. 연결 풀링, AsyncLocalStorage 기반 트랜잭션(@Transactional 데코레이터), 템플릿 리터럴 재할당 방식의 동적 쿼리, 자동 camelCase 변환, dateStrings 옵션, 자동 재연결을 지원합니다. Active 개발 중이며, Bun >=1.0.0이 필요합니다. 기존 ORM과 달리 번들 경량성과 Bun 네이티브 성능을 활용하며, 문자열 기반 raw SQL 대신 템플릿 리터럴 재할당을 강제합니다.

npm install bunqldb
INSTALL
IMPORT
SIG · BUNQLDB
B
bunqldb
databasejavascriptv0.4.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sql
import { sql } from 'bunqldb'
import sql from 'bunqldb'
sql은 named export입니다. default export가 아닙니다.
DB
import { DB } from 'bunqldb'
const DB = require('bunqldb').DB
DB는 클래스로도 사용되나 ESM named export로 가져옵니다. CommonJS require도 가능하지만 ESM 사용을 권장합니다.
Transactional
import { Transactional } from 'bunqldb'
import { transactional } from 'bunqldb'
데코레이터 이름은 대문자 T로 시작하는 PascalCase입니다.
getDbType
import { getDbType } from 'bunqldb'
import { getDbType } from 'bunqldb/helpers'
모든 공개 API는 'bunqldb' 단일 진입점에서 export됩니다.

기본 쿼리, 파라미터 바인딩, INSERT RETURNING, DB 헬퍼, 동적 쿼리 재할당, 트랜잭션 데코레이터 사용법을 보여줍니다.

import { sql, DB } from 'bunqldb'; // .env 또는 환경변수에 DATABASE_URL 설정 필요 // 예: DATABASE_URL=postgres://user:pass@localhost:5432/mydb // 1. 조회 const users = await sql`SELECT * FROM users`; console.log(users); // 2. 파라미터 바인딩 const id = 1; const user = await sql`SELECT * FROM users WHERE id = ${id}`; // 3. INSERT with RETURNING (PostgreSQL) const name = 'Alice'; const email = 'alice@example.com'; const [newUser] = await sql` INSERT INTO users (name, email) VALUES (${name}, ${email}) RETURNING id, name, email `; // 4. DB 헬퍼 사용 (camelCase 자동 변환) const allUsers = await DB.many<{ id: number; name: string; email: string }>(sql`SELECT * FROM users`); // 5. 템플릿 리터럴 재할당 동적 쿼리 let query = sql`SELECT * FROM users WHERE 1=1`; if (name) { query = sql`${query} AND name = ${name}`; } query = sql`${query} ORDER BY created_at DESC LIMIT 10`; const result = await DB.many(query); // 6. 트랜잭션 사용 import { Transactional } from 'bunqldb'; class UserService { @Transactional() async createUser(name: string, email: string) { const [user] = await sql` INSERT INTO users (name, email) VALUES (${name}, ${email}) RETURNING * `; return user; } } // 7. 연결 종료 (선택사항) await DB.close();
Debug
Known issues
breakingbunqldb는 Bun의 내장 sql 클라이언트에 의존하므로 Node.js에서는 동작하지 않습니다.
fix
Bun v1.0.0 이상에서만 실행하세요.
affects: >=0.0.1
breaking문자열 기반 raw SQL 쿼리는 지원되지 않습니다. 모든 쿼리는 템플릿 리터럴(sql`...`)로 작성해야 합니다.
fix
sql`SELECT * FROM users WHERE id = ${id}` 형태로 변경하세요.
affects: >=0.0.1
gotcha자동 camelCase 변환은 DB.many 등 DB 헬퍼 메서드를 사용할 때만 적용됩니다. sql`...`로 직접 조회하면 변환되지 않습니다.
fix
DB.many(sql`...`)처럼 DB 헬퍼를 통해 결과를 받아야 camelCase 변환이 적용됩니다.
affects: >=0.0.1
deprecatedDB.manyPaging 및 DB.manyPagingParams 메서드는 레거시로 간주됩니다.
fix
대신 DB.paginate 또는 DB.cursorPaginate를 사용하세요.
affects: >=0.4.0
gotcha@Transactional 데코레이터는 클래스 메서드에서만 동작하며, 화살표 함수나 일반 함수에는 사용할 수 없습니다.
fix
클래스의 메서드로 정의하고 @Transactional()을 붙이세요.
affects: >=0.0.1
Errors
Common errors & fixes
error: Module 'bunqldb' has no exported member 'sql'
잘못된 import 방식 (default import) 사용
fix
import { sql } from 'bunqldb'로 수정하세요.
TypeError: Cannot read properties of undefined (reading 'query')
DATABASE_URL 또는 DB 환경변수가 설정되지 않아 연결이 초기화되지 않음
fix
Bun 실행 전 .env 파일에 DATABASE_URL을 설정하거나 환경변수를 export하세요.
error: Cannot find package 'bun-types'
bun-types가 설치되지 않음 (peer dependency)
fix
bun add -d bun-types 실행
error: No function overload matches this call. Overload 1 of 2, '(strings: TemplateStringsArray, ...values: any[]): Promise<...>', gave the following error. Argument of type 'string' is not assignable to parameter of type 'TemplateStringsArray'.
sql`...` 대신 일반 문자열로 sql()을 호출함
fix
쿼리는 반드시 템플릿 리터럴로 작성: sql`SELECT * FROM users`
Upgrade
Version history
0.4.2latest on npm
Audit
Dependencies
bun-typesoptional런타임 타입 및 SQL 타입 지원에 필요하며, bunqldb의 TypeScript 타입이 의존함
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
bunqldb — npm install bunqldb · libregistry