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

@sqb/connect

Package Overview
Dependencies
Maintainers
1
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sqb/connect - npm Package Compare versions

Comparing version 4.7.0 to 4.8.0

cjs/orm/commands/delete.command.js

105

cjs/orm/repository.class.js

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

const create_command_js_1 = require("./commands/create.command.js");
const destroy_command_js_1 = require("./commands/destroy.command.js");
const delete_command_js_1 = require("./commands/delete.command.js");
const find_command_js_1 = require("./commands/find.command.js");

@@ -31,3 +31,8 @@ const update_command_js_1 = require("./commands/update.command.js");

return this._execute(async (connection) => {
return this._create(values, { ...options, connection });
const keyValue = await this._create(values, { ...options, connection, returning: true });
const result = keyValue &&
await this._find(keyValue, { ...options, connection });
if (!result)
throw new Error('Unable to insert new row');
return result;
}, options);

@@ -37,3 +42,3 @@ }

return this._execute(async (connection) => {
return this._createOnly(values, { ...options, connection });
await this._create(values, { ...options, connection, returning: false });
}, options);

@@ -51,5 +56,5 @@ }

}
findByPk(keyValue, options) {
find(keyValue, options) {
return this._execute(async (connection) => {
return this._findByPk(keyValue, { ...options, connection });
return this._find(keyValue, { ...options, connection });
}, options);

@@ -59,3 +64,6 @@ }

return this._execute(async (connection) => {
return this._findOne({ ...options, connection });
return await this._findOne({
...options,
connection,
});
}, options);

@@ -65,8 +73,8 @@ }

return this._execute(async (connection) => {
return this._findAll({ ...options, connection });
return this._findMany({ ...options, connection });
}, options);
}
deleteByPk(keyValue, options) {
delete(keyValue, options) {
return this._execute(async (connection) => {
return this._destroy(keyValue, { ...options, connection });
return this._delete(keyValue, { ...options, connection });
}, options);

@@ -76,6 +84,6 @@ }

return this._execute(async (connection) => {
return this._destroyAll({ ...options, connection });
return this._deleteMany({ ...options, connection });
}, options);
}
updateByPk(keyValue, values, options) {
update(keyValue, values, options) {
return this._execute(async (connection) => {

@@ -85,6 +93,6 @@ const opts = { ...options, connection };

if (keyValues)
return this._findByPk(keyValues, opts);
return this._find(keyValues, opts);
}, options);
}
updateByPkOnly(keyValue, values, options) {
updateOnly(keyValue, values, options) {
return this._execute(async (connection) => {

@@ -124,16 +132,2 @@ return !!(await this._updateByPk(keyValue, values, { ...options, connection }));

*/
update(keyValue, values, options) {
return this.updateByPk(keyValue, values, options);
}
/**
*
* @deprecated
*/
updateOnly(keyValue, values, options) {
return this.updateByPkOnly(keyValue, values, options);
}
/**
*
* @deprecated
*/
updateAll(values, options) {

@@ -161,26 +155,11 @@ return this.updateMany(values, options);

throw new TypeError('You must provide values');
await this._emit('before-create', values, options);
const keyValues = await create_command_js_1.CreateCommand.execute({
...options,
entity: this._entity,
values,
returning: true
values
});
const result = keyValues && (await this.findByPk(keyValues, options));
if (!result)
if (options.returning && !keyValues)
throw new Error('Unable to insert new row');
await this._emit('after-create', result, options);
return result;
return keyValues;
}
async _createOnly(values, options) {
if (!values)
throw new TypeError('You must provide values');
await this._emit('before-create', values, options);
await create_command_js_1.CreateCommand.execute({
...options,
entity: this._entity,
values,
returning: false
});
}
async _exists(keyValue, options) {

@@ -206,3 +185,3 @@ const filter = [(0, extract_keyvalues_js_1.extractKeyValues)(this._entity, keyValue, true)];

}
async _findAll(options) {
async _findMany(options) {
return await find_command_js_1.FindCommand.execute({

@@ -214,5 +193,4 @@ ...options,

async _findOne(options) {
const rows = await find_command_js_1.FindCommand.execute({
const rows = await this._findMany({
...options,
entity: this._entity,
limit: 1

@@ -222,3 +200,3 @@ });

}
async _findByPk(keyValue, options) {
async _find(keyValue, options) {
const filter = [(0, extract_keyvalues_js_1.extractKeyValues)(this._entity, keyValue, true)];

@@ -233,4 +211,3 @@ if (options && options.filter) {

}
async _destroy(keyValue, options) {
await this._emit('before-destroy', keyValue, options);
async _delete(keyValue, options) {
const filter = [(0, extract_keyvalues_js_1.extractKeyValues)(this._entity, keyValue, true)];

@@ -243,3 +220,3 @@ if (options && options.filter) {

}
const result = !!(await destroy_command_js_1.DestroyCommand.execute({
return !!(await delete_command_js_1.DeleteCommand.execute({
...options,

@@ -249,8 +226,5 @@ filter,

}));
await this._emit('after-destroy', result, keyValue, options);
return result;
}
async _destroyAll(options) {
await this._emit('before-destroy-all', options);
const rowsAffected = destroy_command_js_1.DestroyCommand.execute({
async _deleteMany(options) {
return delete_command_js_1.DeleteCommand.execute({
...options,

@@ -261,4 +235,2 @@ entity: this._entity,

});
await this._emit('after-destroy-all', rowsAffected, options);
return rowsAffected;
}

@@ -268,3 +240,2 @@ async _updateByPk(keyValue, values, options) {

throw new TypeError('You must provide values');
await this._emit('before-update', keyValue, values, options);
const keyValues = (0, extract_keyvalues_js_1.extractKeyValues)(this._entity, keyValue, true);

@@ -286,3 +257,2 @@ const filter = [keyValues];

});
await this._emit('after-update', rowsAffected, keyValues, options);
return rowsAffected ? keyValues : undefined;

@@ -293,4 +263,3 @@ }

throw new TypeError('You must provide values');
await this._emit('before-update-all', values, options);
const rowsAffected = await update_command_js_1.UpdateCommand.execute({
return await update_command_js_1.UpdateCommand.execute({
...options,

@@ -300,14 +269,4 @@ entity: this._entity,

});
await this._emit('after-update-all', rowsAffected, values, options);
return rowsAffected;
}
async _emit(event, ...args) {
const events = this._entity.eventListeners && this._entity.eventListeners[event];
if (events) {
for (const fn of events) {
await fn(this, ...args);
}
}
}
}
exports.Repository = Repository;

@@ -9,3 +9,3 @@ import { SqbConnection } from '../../client/sqb-connection.js';

connection: SqbConnection;
} & Repository.FindAllOptions;
} & Repository.FindManyOptions;
export declare class FindCommand {

@@ -12,0 +12,0 @@ maxEagerFetch: number;

@@ -8,3 +8,3 @@ import { SqbConnection } from '../../client/sqb-connection.js';

values: any;
} & Repository.UpdateAllOptions;
} & Repository.UpdateManyOptions;
type UpdateCommandContext = {

@@ -11,0 +11,0 @@ entity: EntityMetadata;

@@ -1,2 +0,2 @@

import { Type } from 'ts-gems';
import { StrictOmit, Type } from 'ts-gems';
import { FieldInfoMap } from '../client/field-info-map.js';

@@ -8,2 +8,11 @@ import { SqbClient } from '../client/sqb-client.js';

import { EntityMetadata } from './model/entity-metadata.js';
interface Projection {
pick?: string[];
omit?: string[];
include?: string[];
}
interface Filtering {
filter?: any;
params?: any;
}
export declare namespace Repository {

@@ -14,53 +23,41 @@ type TransformRowFunction = (fields: FieldInfoMap, row: object, obj: object) => void;

}
interface CreateOptions extends CommandOptions {
pick?: string[];
omit?: string[];
include?: string[];
interface CreateOptions extends CommandOptions, Projection {
}
interface CountOptions extends CommandOptions {
filter?: any;
params?: any;
interface CountOptions extends CommandOptions, Filtering {
}
interface ExistsOptions extends CommandOptions {
filter?: any;
params?: any;
interface ExistsOptions extends CommandOptions, Filtering {
}
interface DestroyOptions extends CommandOptions {
filter?: any;
params?: any;
interface DeleteOptions extends CommandOptions, Filtering {
}
interface FindOneOptions extends CommandOptions {
pick?: string[];
omit?: string[];
include?: string[];
filter?: any;
params?: any;
interface DeleteManyOptions extends CommandOptions, Filtering {
}
interface FindOptions extends CommandOptions, Projection, Filtering {
}
interface FindOneOptions extends CommandOptions, Projection, Filtering {
sort?: string[];
offset?: number;
distinct?: boolean;
onTransformRow?: TransformRowFunction;
}
interface FindAllOptions extends FindOneOptions {
interface FindManyOptions extends FindOneOptions {
limit?: number;
distinct?: boolean;
maxEagerFetch?: number;
maxSubQueries?: number;
onTransformRow?: TransformRowFunction;
}
interface GetOptions extends CommandOptions {
pick?: string[];
omit?: string[];
include?: string[];
filter?: any;
params?: any;
interface UpdateOptions extends CommandOptions, Projection, Filtering {
}
interface UpdateOptions extends CommandOptions {
pick?: string[];
omit?: string[];
include?: string[];
filter?: any;
params?: any;
interface UpdateManyOptions extends CommandOptions, Filtering {
}
interface UpdateAllOptions extends CommandOptions {
filter?: any;
params?: any;
}
/**
* @deprecated
*/
type FindAllOptions = FindManyOptions;
/**
* @deprecated
*/
type DestroyOptions = DeleteOptions;
/**
* @deprecated
*/
type UpdateAllOptions = UpdateManyOptions;
}

@@ -81,13 +78,13 @@ interface RepositoryEvents {

create(values: EntityInput<T>, options?: Repository.CreateOptions): Promise<EntityOutput<T>>;
createOnly(values: EntityInput<T>, options?: Repository.CreateOptions): Promise<void>;
createOnly(values: EntityInput<T>, options?: StrictOmit<Repository.CreateOptions, keyof Projection>): Promise<void>;
exists(keyValue: any | Record<string, any>, options?: Repository.ExistsOptions): Promise<boolean>;
count(options?: Repository.CountOptions): Promise<number>;
findByPk(keyValue: any | Record<string, any>, options?: Repository.GetOptions): Promise<EntityOutput<T> | undefined>;
find(keyValue: any | Record<string, any>, options?: Repository.FindOptions): Promise<EntityOutput<T> | undefined>;
findOne(options?: Repository.FindOneOptions): Promise<EntityOutput<T> | undefined>;
findMany(options?: Repository.FindAllOptions): Promise<EntityOutput<T>[]>;
deleteByPk(keyValue: any | Record<string, any>, options?: Repository.DestroyOptions): Promise<boolean>;
deleteMany(options?: Repository.DestroyOptions): Promise<number>;
updateByPk(keyValue: any | Record<string, any>, values: EntityInput<T>, options?: Repository.UpdateOptions): Promise<EntityOutput<T> | undefined>;
updateByPkOnly(keyValue: any | Record<string, any>, values: EntityInput<T>, options?: Repository.UpdateOptions): Promise<boolean>;
updateMany(values: EntityInput<T>, options?: Repository.UpdateAllOptions): Promise<number>;
findMany(options?: Repository.FindManyOptions): Promise<EntityOutput<T>[]>;
delete(keyValue: any | Record<string, any>, options?: Repository.DeleteOptions): Promise<boolean>;
deleteMany(options?: Repository.DeleteManyOptions): Promise<number>;
update(keyValue: any | Record<string, any>, values: EntityInput<T>, options?: Repository.UpdateOptions): Promise<EntityOutput<T> | undefined>;
updateOnly(keyValue: any | Record<string, any>, values: EntityInput<T>, options?: StrictOmit<Repository.UpdateOptions, keyof Projection>): Promise<boolean>;
updateMany(values: EntityInput<T>, options?: Repository.UpdateManyOptions): Promise<number>;
/**

@@ -97,3 +94,3 @@ *

*/
destroy(keyValue: any | Record<string, any>, options?: Repository.DestroyOptions): Promise<boolean>;
destroy(keyValue: any | Record<string, any>, options?: Repository.DeleteOptions): Promise<boolean>;
/**

@@ -103,3 +100,3 @@ *

*/
destroyAll(options?: Repository.DestroyOptions): Promise<number>;
destroyAll(options?: Repository.DeleteManyOptions): Promise<number>;
/**

@@ -109,3 +106,3 @@ *

*/
findAll(options?: Repository.FindAllOptions): Promise<EntityOutput<T>[]>;
findAll(options?: Repository.FindManyOptions): Promise<EntityOutput<T>[]>;
/**

@@ -115,20 +112,8 @@ *

*/
update(keyValue: any | Record<string, any>, values: EntityInput<T>, options?: Repository.UpdateOptions): Promise<EntityOutput<T> | undefined>;
/**
*
* @deprecated
*/
updateOnly(keyValue: any | Record<string, any>, values: EntityInput<T>, options?: Repository.UpdateOptions): Promise<boolean>;
/**
*
* @deprecated
*/
updateAll(values: EntityInput<T>, options?: Repository.UpdateAllOptions): Promise<number>;
updateAll(values: EntityInput<T>, options?: Repository.UpdateManyOptions): Promise<number>;
protected _execute(fn: TransactionFunction, opts?: Repository.CommandOptions): Promise<any>;
protected _create(values: EntityInput<T>, options: Repository.CreateOptions & {
connection: SqbConnection;
}): Promise<EntityOutput<T>>;
protected _createOnly(values: EntityInput<T>, options: Repository.CreateOptions & {
connection: SqbConnection;
}): Promise<void>;
returning?: boolean;
}): Promise<any>;
protected _exists(keyValue: any | Record<string, any>, options: Repository.ExistsOptions & {

@@ -140,3 +125,3 @@ connection: SqbConnection;

}): Promise<number>;
protected _findAll(options: Repository.FindAllOptions & {
protected _findMany(options: Repository.FindManyOptions & {
connection: SqbConnection;

@@ -147,9 +132,9 @@ }): Promise<EntityOutput<T>[]>;

}): Promise<EntityOutput<T> | undefined>;
protected _findByPk(keyValue: any | Record<string, any>, options: Repository.GetOptions & {
protected _find(keyValue: any | Record<string, any>, options: Repository.FindOptions & {
connection: SqbConnection;
}): Promise<EntityOutput<T> | undefined>;
protected _destroy(keyValue: any | Record<string, any>, options: Repository.DestroyOptions & {
protected _delete(keyValue: any | Record<string, any>, options: Repository.DeleteOptions & {
connection: SqbConnection;
}): Promise<boolean>;
protected _destroyAll(options: Repository.DestroyOptions & {
protected _deleteMany(options: Repository.DeleteManyOptions & {
connection: SqbConnection;

@@ -160,7 +145,6 @@ }): Promise<number>;

}): Promise<Record<string, any> | undefined>;
protected _updateAll(values: EntityInput<T>, options: Repository.UpdateAllOptions & {
protected _updateAll(values: EntityInput<T>, options: Repository.UpdateManyOptions & {
connection: SqbConnection;
}): Promise<number>;
protected _emit(event: string, ...args: any[]): Promise<void>;
}
export {};

@@ -5,3 +5,3 @@ import { AsyncEventEmitter, TypedEventEmitterClass } from 'strict-typed-events';

import { CreateCommand } from './commands/create.command.js';
import { DestroyCommand } from './commands/destroy.command.js';
import { DeleteCommand } from './commands/delete.command.js';
import { FindCommand } from './commands/find.command.js';

@@ -28,3 +28,8 @@ import { UpdateCommand } from './commands/update.command.js';

return this._execute(async (connection) => {
return this._create(values, { ...options, connection });
const keyValue = await this._create(values, { ...options, connection, returning: true });
const result = keyValue &&
await this._find(keyValue, { ...options, connection });
if (!result)
throw new Error('Unable to insert new row');
return result;
}, options);

@@ -34,3 +39,3 @@ }

return this._execute(async (connection) => {
return this._createOnly(values, { ...options, connection });
await this._create(values, { ...options, connection, returning: false });
}, options);

@@ -48,5 +53,5 @@ }

}
findByPk(keyValue, options) {
find(keyValue, options) {
return this._execute(async (connection) => {
return this._findByPk(keyValue, { ...options, connection });
return this._find(keyValue, { ...options, connection });
}, options);

@@ -56,3 +61,6 @@ }

return this._execute(async (connection) => {
return this._findOne({ ...options, connection });
return await this._findOne({
...options,
connection,
});
}, options);

@@ -62,8 +70,8 @@ }

return this._execute(async (connection) => {
return this._findAll({ ...options, connection });
return this._findMany({ ...options, connection });
}, options);
}
deleteByPk(keyValue, options) {
delete(keyValue, options) {
return this._execute(async (connection) => {
return this._destroy(keyValue, { ...options, connection });
return this._delete(keyValue, { ...options, connection });
}, options);

@@ -73,6 +81,6 @@ }

return this._execute(async (connection) => {
return this._destroyAll({ ...options, connection });
return this._deleteMany({ ...options, connection });
}, options);
}
updateByPk(keyValue, values, options) {
update(keyValue, values, options) {
return this._execute(async (connection) => {

@@ -82,6 +90,6 @@ const opts = { ...options, connection };

if (keyValues)
return this._findByPk(keyValues, opts);
return this._find(keyValues, opts);
}, options);
}
updateByPkOnly(keyValue, values, options) {
updateOnly(keyValue, values, options) {
return this._execute(async (connection) => {

@@ -121,16 +129,2 @@ return !!(await this._updateByPk(keyValue, values, { ...options, connection }));

*/
update(keyValue, values, options) {
return this.updateByPk(keyValue, values, options);
}
/**
*
* @deprecated
*/
updateOnly(keyValue, values, options) {
return this.updateByPkOnly(keyValue, values, options);
}
/**
*
* @deprecated
*/
updateAll(values, options) {

@@ -158,26 +152,11 @@ return this.updateMany(values, options);

throw new TypeError('You must provide values');
await this._emit('before-create', values, options);
const keyValues = await CreateCommand.execute({
...options,
entity: this._entity,
values,
returning: true
values
});
const result = keyValues && (await this.findByPk(keyValues, options));
if (!result)
if (options.returning && !keyValues)
throw new Error('Unable to insert new row');
await this._emit('after-create', result, options);
return result;
return keyValues;
}
async _createOnly(values, options) {
if (!values)
throw new TypeError('You must provide values');
await this._emit('before-create', values, options);
await CreateCommand.execute({
...options,
entity: this._entity,
values,
returning: false
});
}
async _exists(keyValue, options) {

@@ -203,3 +182,3 @@ const filter = [extractKeyValues(this._entity, keyValue, true)];

}
async _findAll(options) {
async _findMany(options) {
return await FindCommand.execute({

@@ -211,5 +190,4 @@ ...options,

async _findOne(options) {
const rows = await FindCommand.execute({
const rows = await this._findMany({
...options,
entity: this._entity,
limit: 1

@@ -219,3 +197,3 @@ });

}
async _findByPk(keyValue, options) {
async _find(keyValue, options) {
const filter = [extractKeyValues(this._entity, keyValue, true)];

@@ -230,4 +208,3 @@ if (options && options.filter) {

}
async _destroy(keyValue, options) {
await this._emit('before-destroy', keyValue, options);
async _delete(keyValue, options) {
const filter = [extractKeyValues(this._entity, keyValue, true)];

@@ -240,3 +217,3 @@ if (options && options.filter) {

}
const result = !!(await DestroyCommand.execute({
return !!(await DeleteCommand.execute({
...options,

@@ -246,8 +223,5 @@ filter,

}));
await this._emit('after-destroy', result, keyValue, options);
return result;
}
async _destroyAll(options) {
await this._emit('before-destroy-all', options);
const rowsAffected = DestroyCommand.execute({
async _deleteMany(options) {
return DeleteCommand.execute({
...options,

@@ -258,4 +232,2 @@ entity: this._entity,

});
await this._emit('after-destroy-all', rowsAffected, options);
return rowsAffected;
}

@@ -265,3 +237,2 @@ async _updateByPk(keyValue, values, options) {

throw new TypeError('You must provide values');
await this._emit('before-update', keyValue, values, options);
const keyValues = extractKeyValues(this._entity, keyValue, true);

@@ -283,3 +254,2 @@ const filter = [keyValues];

});
await this._emit('after-update', rowsAffected, keyValues, options);
return rowsAffected ? keyValues : undefined;

@@ -290,4 +260,3 @@ }

throw new TypeError('You must provide values');
await this._emit('before-update-all', values, options);
const rowsAffected = await UpdateCommand.execute({
return await UpdateCommand.execute({
...options,

@@ -297,13 +266,3 @@ entity: this._entity,

});
await this._emit('after-update-all', rowsAffected, values, options);
return rowsAffected;
}
async _emit(event, ...args) {
const events = this._entity.eventListeners && this._entity.eventListeners[event];
if (events) {
for (const fn of events) {
await fn(this, ...args);
}
}
}
}
{
"name": "@sqb/connect",
"description": "Multi-dialect database connection framework written with TypeScript",
"version": "4.7.0",
"version": "4.8.0",
"author": "Panates",

@@ -49,3 +49,3 @@ "contributors": [

"peerDependencies": {
"@sqb/builder": "^4.7.0"
"@sqb/builder": "^4.8.0"
},

@@ -52,0 +52,0 @@ "type": "module",

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