@mikro-orm/sqlite
Advanced tools
Comparing version 4.0.7 to 4.1.0
{ | ||
"name": "@mikro-orm/sqlite", | ||
"version": "4.0.7", | ||
"version": "4.1.0", | ||
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.", | ||
@@ -50,8 +50,9 @@ "main": "index.js", | ||
"dependencies": { | ||
"@mikro-orm/knex": "^4.0.7", | ||
"@mikro-orm/knex": "^4.1.0", | ||
"fs-extra": "^9.0.1", | ||
"sqlite3": "^4.2.0" | ||
"sqlite3": "^4.2.0", | ||
"sqlstring-sqlite": "^0.1.1" | ||
}, | ||
"devDependencies": { | ||
"@mikro-orm/core": "^4.0.7" | ||
"@mikro-orm/core": "^4.1.0" | ||
}, | ||
@@ -58,0 +59,0 @@ "peerDependencies": { |
@@ -172,2 +172,3 @@ <h1 align="center"> | ||
- [Inversify + PostgreSQL](https://github.com/PodaruDragos/inversify-example-app) | ||
- [NextJS + MySQL](https://github.com/jonahallibone/mikro-orm-nextjs) | ||
@@ -174,0 +175,0 @@ ### JavaScript Examples |
import { AbstractSqlConnection, Knex } from '@mikro-orm/knex'; | ||
export declare class SqliteConnection extends AbstractSqlConnection { | ||
static readonly RUN_QUERY_RE: RegExp; | ||
connect(): Promise<void>; | ||
@@ -4,0 +5,0 @@ getDefaultClientUrl(): string; |
@@ -52,3 +52,3 @@ "use strict"; | ||
Sqlite3Dialect.prototype.processResponse = (obj, runner) => { | ||
if (obj.method === 'raw' && obj.sql.trim().match('^insert into|update|delete')) { | ||
if (obj.method === 'raw' && obj.sql.trim().match(SqliteConnection.RUN_QUERY_RE)) { | ||
return obj.context; | ||
@@ -78,5 +78,6 @@ } | ||
getCallMethod(obj) { | ||
if (obj.method === 'raw' && obj.sql.trim().match('^insert into|update|delete')) { | ||
if (obj.method === 'raw' && obj.sql.trim().match(SqliteConnection.RUN_QUERY_RE)) { | ||
return 'run'; | ||
} | ||
/* istanbul ignore next */ | ||
switch (obj.method) { | ||
@@ -94,1 +95,3 @@ case 'insert': | ||
exports.SqliteConnection = SqliteConnection; | ||
// static readonly RUN_QUERY_RE = '^insert into|update|delete'; | ||
SqliteConnection.RUN_QUERY_RE = /^insert into|^update|^delete|^truncate/; |
@@ -1,6 +0,7 @@ | ||
import { Configuration } from '@mikro-orm/core'; | ||
import { AbstractSqlDriver } from '@mikro-orm/knex'; | ||
import { AnyEntity, Configuration, EntityData, QueryResult, Transaction } from '@mikro-orm/core'; | ||
import { AbstractSqlDriver, Knex } from '@mikro-orm/knex'; | ||
import { SqliteConnection } from './SqliteConnection'; | ||
export declare class SqliteDriver extends AbstractSqlDriver<SqliteConnection> { | ||
constructor(config: Configuration); | ||
nativeInsertMany<T extends AnyEntity<T>>(entityName: string, data: EntityData<T>[], ctx?: Transaction<Knex.Transaction>, processCollections?: boolean): Promise<QueryResult>; | ||
} |
@@ -11,3 +11,13 @@ "use strict"; | ||
} | ||
async nativeInsertMany(entityName, data, ctx, processCollections = true) { | ||
var _a; | ||
const res = await super.nativeInsertMany(entityName, data, ctx, processCollections); | ||
const pks = this.getPrimaryKeyFields(entityName); | ||
const first = res.insertId - data.length + 1; | ||
res.rows = (_a = res.rows) !== null && _a !== void 0 ? _a : []; | ||
data.forEach((item, idx) => { var _a; return res.rows[idx] = { [pks[0]]: (_a = item[pks[0]]) !== null && _a !== void 0 ? _a : first + idx }; }); | ||
res.row = res.rows[0]; | ||
return res; | ||
} | ||
} | ||
exports.SqliteDriver = SqliteDriver; |
@@ -0,1 +1,2 @@ | ||
import { EntityProperty } from '@mikro-orm/core'; | ||
import { AbstractSqlPlatform } from '@mikro-orm/knex'; | ||
@@ -8,3 +9,2 @@ import { SqliteSchemaHelper } from './SqliteSchemaHelper'; | ||
requiresNullableForAlteringColumn(): boolean; | ||
allowsMultiInsert(): boolean; | ||
usesDefaultKeyword(): boolean; | ||
@@ -20,2 +20,5 @@ getCurrentTimestampSQL(length: number): string; | ||
processDateProperty(value: unknown): string | number | Date; | ||
quoteVersionValue(value: Date | number, prop: EntityProperty): Date | string | number; | ||
requiresValuesKeyword(): boolean; | ||
quoteValue(value: any): string; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SqlitePlatform = void 0; | ||
// @ts-ignore | ||
const sqlstring_sqlite_1 = require("sqlstring-sqlite"); | ||
const core_1 = require("@mikro-orm/core"); | ||
const knex_1 = require("@mikro-orm/knex"); | ||
@@ -16,5 +19,2 @@ const SqliteSchemaHelper_1 = require("./SqliteSchemaHelper"); | ||
} | ||
allowsMultiInsert() { | ||
return false; | ||
} | ||
usesDefaultKeyword() { | ||
@@ -41,3 +41,22 @@ return false; | ||
} | ||
quoteVersionValue(value, prop) { | ||
if (prop.type.toLowerCase() === 'date') { | ||
return sqlstring_sqlite_1.escape(value, true, this.timezone).replace(/^'|\.\d{3}'$/g, ''); | ||
} | ||
return value; | ||
} | ||
requiresValuesKeyword() { | ||
return true; | ||
} | ||
quoteValue(value) { | ||
/* istanbul ignore if */ | ||
if (core_1.Utils.isPlainObject(value) || Array.isArray(value)) { | ||
return sqlstring_sqlite_1.escape(JSON.stringify(value), true, this.timezone); | ||
} | ||
if (value instanceof Date) { | ||
return '' + +value; | ||
} | ||
return sqlstring_sqlite_1.escape(value, true, this.timezone); | ||
} | ||
} | ||
exports.SqlitePlatform = SqlitePlatform; |
35856
432
413
5
+ Addedsqlstring-sqlite@^0.1.1
+ Addedsqlstring-sqlite@0.1.1(transitive)
Updated@mikro-orm/knex@^4.1.0