@drizzle-adapter/sqlite-core

中文文档
1.1.1发布于 2026/03/26MITTypeScriptES Module近 30 天下载 2万

Shared SQLite functionality for the Drizzle Adapter ecosystem.

原始使用文档
文档目录12 节
  1. Overview
  2. Purpose
  3. Installation
  4. For Adapter Developers
  5. Data Types
  6. Error Handling
  7. Query Building
  8. Type Mapping
  9. SQLite-Specific Features
  10. Date/Time Utilities
  11. Contributing
  12. Related Packages

@drizzle-adapter/sqlite-core

Shared SQLite functionality for the Drizzle Adapter ecosystem.

Overview

The @drizzle-adapter/sqlite-core package provides shared SQLite functionality used by SQLite-compatible adapters in the Drizzle Adapter ecosystem. This package is an internal dependency used by:

Purpose

This package standardizes SQLite-specific functionality across different SQLite-compatible adapters:

  • Common SQLite data type definitions
  • Shared SQLite query building logic
  • Unified SQLite error handling
  • Common SQLite utility functions

Installation

# This package is typically not installed directly but as a dependency of SQLite adapters
pnpm install @drizzle-adapter/sqlite-core

For Adapter Developers

If you're developing a new SQLite-compatible adapter for the Drizzle Adapter ecosystem, you should use this package to ensure consistency with other SQLite adapters:

import { SQLiteDrizzleDataTypes } from '@drizzle-adapter/sqlite-core';

export class YourSQLiteAdapter implements DrizzleAdapterInterface {
  public getDataTypes(): SQLiteDrizzleDataTypes {
    return new SQLiteDrizzleDataTypes();
  }
  
  // ... rest of your adapter implementation
}

Data Types

The package provides standardized SQLite data type definitions:

const dataTypes = new SQLiteDrizzleDataTypes();

const table = dataTypes.dbTable('example', {
  // Numeric types
  id: dataTypes.dbInteger('id').primaryKey().autoincrement(),
  count: dataTypes.dbInteger('count'),
  amount: dataTypes.dbReal('amount'),
  
  // String types
  name: dataTypes.dbText('name'),
  description: dataTypes.dbText('description'),
  
  // Date/Time types (stored as INTEGER or TEXT)
  createdAt: dataTypes.dbInteger('created_at')
    .default(sql`(strftime('%s', 'now'))`),
  updatedAt: dataTypes.dbText('updated_at')
    .default(sql`CURRENT_TIMESTAMP`),
  
  // SQLite-specific handling
  json: dataTypes.dbText('json'), // JSON stored as TEXT
  isActive: dataTypes.dbInteger('is_active'), // Boolean as INTEGER
  blob: dataTypes.dbBlob('data') // Binary data
});

Error Handling

The package provides unified error handling for SQLite-specific errors:

import { handleSQLiteError } from '@drizzle-adapter/sqlite-core';

try {
  // Your database operation
} catch (error) {
  throw handleSQLiteError(error);
}

Query Building

The package includes utilities for building SQLite-specific queries:

import { 
  buildInsertQuery,
  buildUpdateQuery,
  buildDeleteQuery,
  buildSelectQuery,
  buildFTSQuery
} from '@drizzle-adapter/sqlite-core';

// Build INSERT query
const insertQuery = buildInsertQuery(table, data);

// Build UPDATE query with JSON operations
const updateQuery = buildUpdateQuery(table, {
  json: sql`json_set(json, '$.key', 'value')`
});

// Build DELETE query with conditions
const deleteQuery = buildDeleteQuery(table, conditions);

// Build SELECT query with joins
const selectQuery = buildSelectQuery({
  table,
  joins: [...],
  conditions: [...],
  orderBy: [...]
});

// Build full-text search query
const searchQuery = buildFTSQuery({
  table: 'posts_fts',
  searchTerm: 'search term',
  columns: ['title', 'content']
});

Type Mapping

The package handles SQLite-specific type mapping:

import { mapSQLiteType } from '@drizzle-adapter/sqlite-core';

// Map JavaScript types to SQLite types
const sqliteType = mapSQLiteType(value);

// Map SQLite types to JavaScript types
const jsValue = mapToJavaScript(sqliteValue, sqliteType);

// Handle JSON serialization
const jsonText = serializeJSON(value);
const jsonValue = deserializeJSON(text);

// Handle date/time
const timestamp = dateToUnixTimestamp(date);
const date = unixTimestampToDate(timestamp);

SQLite-Specific Features

import { 
  createFTSTable,
  createFTSIndex,
  handleJSONOperations,
  handleDateTimeOperations
} from '@drizzle-adapter/sqlite-core';

// Create FTS table
const ftsSQL = createFTSTable('posts_fts', ['title', 'content']);

// Create FTS index
const indexSQL = createFTSIndex('posts_fts_idx', 'posts', ['title', 'content']);

// Handle JSON operations
const jsonCondition = handleJSONOperations(column, path, value);

// Handle date/time operations
const dateCondition = handleDateTimeOperations(column, operator, value);

Date/Time Utilities

import { 
  getCurrentTimestamp,
  formatDateTime,
  parseDateTime,
  addInterval
} from '@drizzle-adapter/sqlite-core';

// Get current timestamp
const now = getCurrentTimestamp();

// Format date/time
const formatted = formatDateTime(date, format);

// Parse date/time
const date = parseDateTime(text, format);

// Add interval
const future = addInterval(date, { days: 7, hours: 12 });

Contributing

This package is maintained as part of the Drizzle Adapter ecosystem. If you'd like to contribute:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

版本与发布记录

@drizzle-adapter/sqlite-core 共发布 13 个版本,首次发布于 2024/12/03;过去 12 个月发布了 1 个版本。

版本发布日期距今
1.1.1latest2026/03/267 个月前
1.0.152025/09/211.1 年前
1.0.142025/07/171.3 年前
1.0.122025/07/121.3 年前
1.0.112025/07/121.3 年前
1.0.92025/07/041.4 年前

关于 @drizzle-adapter/sqlite-core 的常见问题

@drizzle-adapter/sqlite-core 是什么?

Shared SQLite functionality for the Drizzle Adapter ecosystem.

如何安装 @drizzle-adapter/sqlite-core?

在项目目录运行 npm install @drizzle-adapter/sqlite-core,或使用 pnpm add / yarn add / bun add。

@drizzle-adapter/sqlite-core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@drizzle-adapter/sqlite-core 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@drizzle-adapter/sqlite-core 可以商用吗?

@drizzle-adapter/sqlite-core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@drizzle-adapter/sqlite-core 的下载量有多少?

根据 npm 官方下载统计,@drizzle-adapter/sqlite-core 在 2026/10/13 – 2026/11/11 这 30 天内被下载 20,346 次,日均约 678 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@drizzle-adapter/sqlite-core 还在维护吗?

最新版本 1.1.1 发布于 2026/03/26(7 个月前);至今共发布 13 个版本,其中过去 12 个月发布了 1 个;首次发布于 2024/12/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。