Latest Supply Chain Attack:Mini Shai-Hulud Hits @antv npm Packages, 639 Versions Compromised.Learn More
Sign In

@drizzle-adapter/sqlite-core

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@drizzle-adapter/sqlite-core

Shared SQLite functionality for the Drizzle Adapter ecosystem.

latest
npmnpm
Version
1.1.1
Version published
Weekly downloads
236
293.33%
Maintainers
1
Weekly downloads
 
Created
Source

@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:

  • @drizzle-adapter/libsql
  • @drizzle-adapter/d1

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:

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

FAQs

Package last updated on 25 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts