Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

drizzle-orm-sqlite

Package Overview
Dependencies
Maintainers
3
Versions
143
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

drizzle-orm-sqlite - npm Package Compare versions

Comparing version 0.12.0-beta.8 to 0.12.0-beta.9

12

better-sqlite3/session.d.ts
import { Database, RunResult } from 'better-sqlite3';
import { Logger } from 'drizzle-orm';
import { SQL } from 'drizzle-orm/sql';
import { Query, SQL } from 'drizzle-orm/sql';
import { SQLiteDialect } from '../dialect';
import { SQLiteSession, SQLiteStatement } from '../session';
import { PreparedQuery, SQLiteSession } from '../session';
export interface SQLiteDefaultSessionOptions {

@@ -14,6 +14,6 @@ logger?: Logger;

constructor(client: Database, dialect: SQLiteDialect, options?: SQLiteDefaultSessionOptions);
run(query: SQL): RunResult;
all<T extends any[] = unknown[]>(query: SQL): T[];
allObjects<T = unknown>(query: SQL): T[];
prepare<T>(query: SQL): SQLiteStatement<T>;
run(query: SQL | PreparedQuery): RunResult;
all<T extends any[] = unknown[]>(query: SQL | PreparedQuery): T[];
allObjects<T = unknown>(query: SQL | PreparedQuery): T[];
prepareQuery(query: Query): PreparedQuery;
}

@@ -5,3 +5,3 @@ "use strict";

const drizzle_orm_1 = require("drizzle-orm");
const session_1 = require("../session");
const sql_1 = require("drizzle-orm/sql");
class SQLiteDefaultSession {

@@ -15,11 +15,11 @@ constructor(client, dialect, options = {}) {

run(query) {
const preparedQuery = this.dialect.prepareSQL(query);
this.logger.logQuery(preparedQuery.sql, preparedQuery.params);
const stmt = this.client.prepare(preparedQuery.sql);
const preparedQuery = query instanceof sql_1.SQL ? this.prepareQuery(this.dialect.sqlToQuery(query)) : query;
this.logger.logQuery(preparedQuery.queryString, preparedQuery.params);
const stmt = preparedQuery.stmt;
return stmt.run(...preparedQuery.params);
}
all(query) {
const preparedQuery = this.dialect.prepareSQL(query);
this.logger.logQuery(preparedQuery.sql, preparedQuery.params);
const stmt = this.client.prepare(preparedQuery.sql);
const preparedQuery = query instanceof sql_1.SQL ? this.prepareQuery(this.dialect.sqlToQuery(query)) : query;
this.logger.logQuery(preparedQuery.queryString, preparedQuery.params);
const stmt = preparedQuery.stmt;
stmt.raw();

@@ -29,11 +29,10 @@ return stmt.all(...preparedQuery.params);

allObjects(query) {
const preparedQuery = this.dialect.prepareSQL(query);
this.logger.logQuery(preparedQuery.sql, preparedQuery.params);
const stmt = this.client.prepare(preparedQuery.sql);
const preparedQuery = query instanceof sql_1.SQL ? this.prepareQuery(this.dialect.sqlToQuery(query)) : query;
this.logger.logQuery(preparedQuery.queryString, preparedQuery.params);
const stmt = preparedQuery.stmt;
return stmt.all(...preparedQuery.params);
}
prepare(query) {
const preparedQuery = this.dialect.prepareSQL(query);
this.logger.logQuery(preparedQuery.sql, preparedQuery.params);
return new session_1.SQLiteStatement(this.client.prepare(preparedQuery.sql).bind(preparedQuery.params));
prepareQuery(query) {
const stmt = this.client.prepare(query.sql);
return { stmt, queryString: query.sql, params: query.params };
}

@@ -40,0 +39,0 @@ }

/// <reference types="bun-types" />
import { Database } from 'bun:sqlite';
import { Logger } from 'drizzle-orm';
import { SQL } from 'drizzle-orm/sql';
import { Query, SQL } from 'drizzle-orm/sql';
import { SQLiteDialect } from '../dialect';
import { RunResult, SQLiteSession, SQLiteStatement } from '../session';
import { PreparedQuery, RunResult, SQLiteSession } from '../session';
export interface SQLiteBunSessionOptions {

@@ -15,6 +15,6 @@ logger?: Logger;

constructor(client: Database, dialect: SQLiteDialect, options?: SQLiteBunSessionOptions);
run(query: SQL): RunResult;
all<T extends any[] = unknown[]>(query: SQL): T[];
allObjects<T = unknown>(query: SQL): T[];
prepare<T>(query: SQL): SQLiteStatement<T>;
run(query: SQL | PreparedQuery): RunResult;
all<T extends any[] = unknown[]>(query: SQL | PreparedQuery): T[];
allObjects<T = unknown>(query: SQL | PreparedQuery): T[];
prepareQuery(query: Query): PreparedQuery;
}

@@ -5,3 +5,3 @@ "use strict";

const drizzle_orm_1 = require("drizzle-orm");
const session_1 = require("../session");
const sql_1 = require("drizzle-orm/sql");
class SQLiteBunSession {

@@ -15,21 +15,23 @@ constructor(client, dialect, options = {}) {

run(query) {
const preparedQuery = this.dialect.prepareSQL(query);
this.logger.logQuery(preparedQuery.sql, preparedQuery.params);
this.client.exec(preparedQuery.sql, ...preparedQuery.params);
const preparedQuery = query instanceof sql_1.SQL ? this.prepareQuery(this.dialect.sqlToQuery(query)) : query;
this.logger.logQuery(preparedQuery.queryString, preparedQuery.params);
const stmt = preparedQuery.stmt;
stmt.run(...preparedQuery.params);
return { changes: 0, lastInsertRowid: 0 };
}
all(query) {
const preparedQuery = this.dialect.prepareSQL(query);
this.logger.logQuery(preparedQuery.sql, preparedQuery.params);
return this.client.prepare(preparedQuery.sql, ...preparedQuery.params).values();
const preparedQuery = query instanceof sql_1.SQL ? this.prepareQuery(this.dialect.sqlToQuery(query)) : query;
this.logger.logQuery(preparedQuery.queryString, preparedQuery.params);
const stmt = preparedQuery.stmt;
return stmt.values();
}
allObjects(query) {
const preparedQuery = this.dialect.prepareSQL(query);
this.logger.logQuery(preparedQuery.sql, preparedQuery.params);
return this.client.prepare(preparedQuery.sql, ...preparedQuery.params).all();
const preparedQuery = query instanceof sql_1.SQL ? this.prepareQuery(this.dialect.sqlToQuery(query)) : query;
this.logger.logQuery(preparedQuery.queryString, preparedQuery.params);
const stmt = preparedQuery.stmt;
return stmt.all();
}
prepare(query) {
const preparedQuery = this.dialect.prepareSQL(query);
this.logger.logQuery(preparedQuery.sql, preparedQuery.params);
return new session_1.SQLiteStatement(this.client.prepare(preparedQuery.sql, ...preparedQuery.params));
prepareQuery(query) {
const stmt = this.client.prepare(query.sql);
return { stmt, queryString: query.sql, params: query.params };
}

@@ -36,0 +38,0 @@ }

import { MigrationMeta } from 'drizzle-orm';
import { PreparedQuery, SQL } from 'drizzle-orm/sql';
import { Query, SQL } from 'drizzle-orm/sql';
import { SQLiteDatabase } from './db';

@@ -31,3 +31,3 @@ import { SQLiteSelectFields, SQLiteSelectFieldsOrdered } from './operations';

buildInsertQuery({ table, values, onConflict, returning }: SQLiteInsertConfig): SQL;
prepareSQL(sql: SQL): PreparedQuery;
sqlToQuery(sql: SQL): Query;
}

@@ -198,3 +198,3 @@ "use strict";

}
prepareSQL(sql) {
sqlToQuery(sql) {
return sql.toQuery({

@@ -201,0 +201,0 @@ escapeName: this.escapeName,

{
"name": "drizzle-orm-sqlite",
"version": "0.12.0-beta.8",
"version": "0.12.0-beta.9",
"description": "Drizzle ORM package for SQLite database",

@@ -5,0 +5,0 @@ "main": "index.js",

import { RunResult } from 'better-sqlite3';
import { PreparedQuery, SQL, SQLWrapper } from 'drizzle-orm/sql';
import { Query, SQL, SQLWrapper } from 'drizzle-orm/sql';
import { SQLiteDialect } from '../dialect';

@@ -17,2 +17,3 @@ import { SelectResultFields, SQLiteSelectFields, SQLiteSelectFieldsOrdered } from '../operations';

private config;
private preparedQuery;
constructor(table: TTable, session: SQLiteSession, dialect: SQLiteDialect);

@@ -23,4 +24,5 @@ where(where: SQL | undefined): Omit<this, 'where'>;

getSQL(): SQL;
getQuery(): PreparedQuery;
execute(): TReturn;
getQuery(): Query;
prepare(): Omit<this, 'prepare'>;
execute(placeholderValues?: Record<string, unknown>): TReturn;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SQLiteDelete = void 0;
const sql_1 = require("drizzle-orm/sql");
const utils_1 = require("drizzle-orm/utils");

@@ -26,6 +27,15 @@ const table_1 = require("../table");

getQuery() {
return this.dialect.prepareSQL(this.getSQL());
return this.dialect.sqlToQuery(this.getSQL());
}
execute() {
const query = this.dialect.buildDeleteQuery(this.config);
prepare() {
if (!this.preparedQuery) {
this.preparedQuery = this.session.prepareQuery(this.getQuery());
}
return this;
}
execute(placeholderValues) {
this.prepare();
let query = this.preparedQuery;
const params = (0, sql_1.fillPlaceholders)(query.params, placeholderValues !== null && placeholderValues !== void 0 ? placeholderValues : {});
query = Object.assign(Object.assign({}, query), { params });
const { returning } = this.config;

@@ -32,0 +42,0 @@ if (returning) {

import { RunResult } from 'better-sqlite3';
import { Param, PreparedQuery, SQL, SQLWrapper } from 'drizzle-orm/sql';
import { Param, Placeholder, Query, SQL, SQLWrapper } from 'drizzle-orm/sql';
import { Simplify } from 'drizzle-orm/utils';

@@ -17,3 +17,3 @@ import { SQLiteDialect } from '../dialect';

export declare type SQLiteInsertValue<TTable extends AnySQLiteTable> = Simplify<{
[Key in keyof InferModel<TTable, 'insert'>]: InferModel<TTable, 'insert'>[Key] | SQL;
[Key in keyof InferModel<TTable, 'insert'>]: InferModel<TTable, 'insert'>[Key] | SQL | Placeholder;
}>;

@@ -33,2 +33,3 @@ export declare class SQLiteInsertBuilder<TTable extends AnySQLiteTable> {

private config;
private preparedQuery;
constructor(table: TTable, values: SQLiteInsertConfig['values'], session: SQLiteSession, dialect: SQLiteDialect);

@@ -47,4 +48,5 @@ returning(): Omit<SQLiteInsert<TTable, InferModel<TTable>[]>, 'returning' | `onConflict${string}`>;

getSQL(): SQL;
getQuery(): PreparedQuery;
execute(): TReturn;
getQuery(): Query;
prepare(): Omit<this, 'prepare'>;
execute(placeholderValues?: Record<string, unknown>): TReturn;
}

@@ -65,6 +65,15 @@ "use strict";

getQuery() {
return this.dialect.prepareSQL(this.getSQL());
return this.dialect.sqlToQuery(this.getSQL());
}
execute() {
const query = this.getSQL();
prepare() {
if (!this.preparedQuery) {
this.preparedQuery = this.session.prepareQuery(this.getQuery());
}
return this;
}
execute(placeholderValues) {
this.prepare();
let query = this.preparedQuery;
const params = (0, sql_1.fillPlaceholders)(query.params, placeholderValues !== null && placeholderValues !== void 0 ? placeholderValues : {});
query = Object.assign(Object.assign({}, query), { params });
const { returning } = this.config;

@@ -71,0 +80,0 @@ if (returning) {

@@ -1,5 +0,5 @@

import { PreparedQuery, SQL, SQLWrapper } from 'drizzle-orm/sql';
import { Placeholder, Query, SQL, SQLWrapper } from 'drizzle-orm/sql';
import { SQLiteDialect } from '../dialect';
import { SelectResultFields, SQLiteSelectFields, SQLiteSelectFieldsOrdered } from '../operations';
import { SQLiteSession, SQLiteStatement } from '../session';
import { SQLiteSession } from '../session';
import { AnySQLiteTable, GetTableConfig } from '../table';

@@ -11,4 +11,4 @@ import { AppendToResult, JoinNullability, JoinsValue, JoinType, SelectResult } from './select.types';

table: AnySQLiteTable;
limit?: number;
offset?: number;
limit?: number | Placeholder;
offset?: number | Placeholder;
joins: Record<string, JoinsValue>;

@@ -25,2 +25,3 @@ orderBy: SQL[];

private joinsNotNullable;
private preparedQuery;
constructor(table: SQLiteSelectConfig['table'], fields: SQLiteSelectConfig['fields'], session: SQLiteSession, dialect: SQLiteDialect);

@@ -35,8 +36,8 @@ private createJoin;

orderBy(...columns: SQL[]): Omit<this, 'where' | `${JoinType}Join` | 'orderBy'>;
limit(limit: number): Omit<this, 'where' | `${JoinType}Join` | 'limit'>;
offset(offset: number): Omit<this, 'where' | `${JoinType}Join` | 'offset'>;
limit(limit: number | Placeholder): Omit<this, 'where' | `${JoinType}Join` | 'limit'>;
offset(offset: number | Placeholder): Omit<this, 'where' | `${JoinType}Join` | 'offset'>;
getSQL(): SQL;
getQuery(): PreparedQuery;
prepare(): SQLiteStatement<SelectResult<TTable, TResult, TInitialSelectResultFields, TJoinsNotNullable>>;
execute(): SelectResult<TTable, TResult, TInitialSelectResultFields, TJoinsNotNullable>;
getQuery(): Query;
prepare(): Omit<this, 'prepare'>;
execute(placeholderValues?: Record<string, unknown>): SelectResult<TTable, TResult, TInitialSelectResultFields, TJoinsNotNullable>;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SQLiteSelect = void 0;
const sql_1 = require("drizzle-orm/sql");
const utils_1 = require("drizzle-orm/utils");

@@ -78,10 +79,15 @@ const table_1 = require("../table");

const query = this.dialect.buildSelectQuery(this.config);
return this.dialect.prepareSQL(query);
return this.dialect.sqlToQuery(query);
}
prepare() {
return this.session.prepare(this.getSQL());
if (!this.preparedQuery) {
this.preparedQuery = this.session.prepareQuery(this.getQuery());
}
return this;
}
execute() {
const query = this.dialect.buildSelectQuery(this.config);
const result = this.session.all(query);
execute(placeholderValues) {
this.prepare();
const query = this.preparedQuery;
const params = (0, sql_1.fillPlaceholders)(query.params, placeholderValues !== null && placeholderValues !== void 0 ? placeholderValues : {});
const result = this.session.all(Object.assign(Object.assign({}, query), { params }));
return result.map((row) => (0, utils_1.mapResultRow)(this.config.fields, row, this.joinsNotNullable));

@@ -88,0 +94,0 @@ }

import { RunResult } from 'better-sqlite3';
import { GetColumnData } from 'drizzle-orm';
import { Param, PreparedQuery, SQL, SQLWrapper } from 'drizzle-orm/sql';
import { Param, Query, SQL, SQLWrapper } from 'drizzle-orm/sql';
import { Simplify } from 'drizzle-orm/utils';

@@ -33,2 +33,3 @@ import { SQLiteDialect } from '../dialect';

private config;
private preparedQuery;
constructor(table: TTable, set: SQLiteUpdateSet, session: SQLiteSession, dialect: SQLiteDialect);

@@ -39,4 +40,5 @@ where(where: SQL | undefined): Omit<this, 'where'>;

getSQL(): SQL;
getQuery(): PreparedQuery;
execute(): TReturn;
getQuery(): Query;
prepare(): Omit<this, 'prepare'>;
execute(placeholderValues?: Record<string, unknown>): TReturn;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SQLiteUpdate = exports.SQLiteUpdateBuilder = void 0;
const sql_1 = require("drizzle-orm/sql");
const utils_1 = require("drizzle-orm/utils");

@@ -37,6 +38,15 @@ const table_1 = require("../table");

getQuery() {
return this.dialect.prepareSQL(this.getSQL());
return this.dialect.sqlToQuery(this.getSQL());
}
execute() {
const query = this.dialect.buildUpdateQuery(this.config);
prepare() {
if (!this.preparedQuery) {
this.preparedQuery = this.session.prepareQuery(this.getQuery());
}
return this;
}
execute(placeholderValues) {
this.prepare();
let query = this.preparedQuery;
const params = (0, sql_1.fillPlaceholders)(query.params, placeholderValues !== null && placeholderValues !== void 0 ? placeholderValues : {});
query = Object.assign(Object.assign({}, query), { params });
const { returning } = this.config;

@@ -43,0 +53,0 @@ if (returning) {

/// <reference types="bun-types" />
import type { Statement as BetterSqliteStatement } from 'better-sqlite3';
import type { Statement as BetterSQLiteStatement } from 'better-sqlite3';
import type { Statement as BunStatement } from 'bun:sqlite';
import { SQL } from 'drizzle-orm/sql';
import { Query, SQL } from 'drizzle-orm/sql';
export interface RunResult {

@@ -9,12 +9,16 @@ changes: number;

}
export declare class SQLiteStatement<T> {
private statement;
constructor(statement: BunStatement | BetterSqliteStatement);
execute(): T;
export interface PreparedQuery {
stmt: BunStatement<unknown> | BetterSQLiteStatement;
queryString: string;
params: unknown[];
}
export interface PreparedQueryExecuteConfig {
stmt: PreparedQuery;
placeholderValues: Record<string, unknown>;
}
export interface SQLiteSession {
run(query: SQL): RunResult;
all<T extends any[] = unknown[]>(query: SQL): T[];
allObjects<T = unknown>(query: SQL): T[];
prepare<T>(query: SQL): SQLiteStatement<T>;
run(query: SQL | PreparedQuery): RunResult;
all<T extends any[] = unknown[]>(query: SQL | PreparedQuery): T[];
allObjects<T = unknown>(query: SQL | PreparedQuery): T[];
prepareQuery(query: Query): PreparedQuery;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SQLiteStatement = void 0;
class SQLiteStatement {
constructor(statement) {
this.statement = statement;
}
execute() {
return this.statement.all();
}
}
exports.SQLiteStatement = SQLiteStatement;
//# sourceMappingURL=session.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc