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

mikro-orm

Package Overview
Dependencies
Maintainers
1
Versions
3403
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mikro-orm - npm Package Compare versions

Comparing version 0.5.6 to 0.6.0

13

dist/EntityManager.js

@@ -46,12 +46,17 @@ "use strict";

async find(entityName, where = {}, populate = [], orderBy = {}, limit = null, offset = 0) {
let query = `db.getCollection('${this.metadata[entityName].collection}').find(${JSON.stringify(where)})`;
const resultSet = this.getCollection(entityName).find(where);
if (Object.keys(orderBy).length > 0) {
query += `.sort(${JSON.stringify(orderBy)})`;
resultSet.sort(orderBy);
}
if (limit !== null) {
query += `.limit(${limit})`;
resultSet.limit(limit);
}
if (offset !== null) {
query += `.skip(${offset})`;
resultSet.skip(offset);
}
this.options.logger(`[query-logger] ${query}.toArray();`);
const results = await resultSet.toArray();

@@ -76,2 +81,4 @@ const ret = [];

}
const query = `db.getCollection('${this.metadata[entityName].collection}').find(${JSON.stringify(where)}).limit(1).next();`;
this.options.logger(`[query-logger] ${query}`);
const data = await this.getCollection(entityName).find(where).limit(1).next();

@@ -113,2 +120,4 @@ if (!data) {

}
const query = `db.getCollection('${this.metadata[entityName].collection}').deleteMany(${JSON.stringify(where)});`;
this.options.logger(`[query-logger] ${query}`);
const result = await this.getCollection(this.metadata[entityName].collection).deleteMany(where);

@@ -119,2 +128,4 @@ return result.deletedCount;

this.runHooks('beforeDelete', entity);
const query = `db.getCollection('${this.metadata[entity.constructor.name].collection}').deleteOne({ _id: ${entity._id} });`;
this.options.logger(`[query-logger] ${query}`);
const result = await this.getCollection(this.metadata[entity.constructor.name].collection).deleteOne({ _id: entity._id });

@@ -127,2 +138,4 @@ delete this.identityMap[`${entity.constructor.name}-${entity.id}`];

async count(entityName, where) {
const query = `db.getCollection('${this.metadata[entityName].collection}').count(${JSON.stringify(where)});`;
this.options.logger(`[query-logger] ${query}`);
return this.getCollection(this.metadata[entityName].collection).count(where);

@@ -129,0 +142,0 @@ }

1

dist/MikroORM.js

@@ -53,2 +53,3 @@ "use strict";

this.db = this.client.db(this.options.dbName);
this.options.logger(`MikroORM: successfully connected to database ${this.options.dbName} on ${this.options.clientUrl}`);
return this.db;

@@ -55,0 +56,0 @@ }

@@ -133,5 +133,9 @@ "use strict";

changeSet.entity.updatedAt = changeSet.payload.updatedAt = new Date();
const query = `db.getCollection('${changeSet.collection}').updateOne({ _id: ${changeSet.entity._id} }, { $set: ${JSON.stringify(changeSet.payload)} });`;
this.em.options.logger(`[query-logger] ${query}`);
await this.em.getCollection(changeSet.collection).updateOne({ _id: changeSet.entity._id }, { $set: changeSet.payload });
}
else {
const query = `db.getCollection('${changeSet.collection}').insertOne(${JSON.stringify(changeSet.payload)});`;
this.em.options.logger(`[query-logger] ${query}`);
const result = await this.em.getCollection(changeSet.collection).insertOne(changeSet.payload);

@@ -138,0 +142,0 @@ changeSet.entity._id = result.insertedId;

@@ -51,5 +51,7 @@ import { Collection as MongoCollection, Db, FilterQuery, ObjectID } from 'mongodb';

async find<T extends BaseEntity>(entityName: string, where = {} as FilterQuery<T>, populate: string[] = [], orderBy: { [k: string]: 1 | -1 } = {}, limit: number = null, offset = 0): Promise<T[]> {
let query = `db.getCollection('${this.metadata[entityName].collection}').find(${JSON.stringify(where)})`;
const resultSet = this.getCollection(entityName).find(where);
if (Object.keys(orderBy).length > 0) {
query += `.sort(${JSON.stringify(orderBy)})`;
resultSet.sort(orderBy);

@@ -59,2 +61,3 @@ }

if (limit !== null) {
query += `.limit(${limit})`;
resultSet.limit(limit);

@@ -64,5 +67,7 @@ }

if (offset !== null) {
query += `.skip(${offset})`;
resultSet.skip(offset);
}
this.options.logger(`[query-logger] ${query}.toArray();`);
const results = await resultSet.toArray();

@@ -93,2 +98,4 @@ const ret: T[] = [];

const query = `db.getCollection('${this.metadata[entityName].collection}').find(${JSON.stringify(where)}).limit(1).next();`;
this.options.logger(`[query-logger] ${query}`);
const data = await this.getCollection(entityName).find(where as FilterQuery<T>).limit(1).next();

@@ -144,2 +151,4 @@

const query = `db.getCollection('${this.metadata[entityName].collection}').deleteMany(${JSON.stringify(where)});`;
this.options.logger(`[query-logger] ${query}`);
const result = await this.getCollection(this.metadata[entityName].collection).deleteMany(where);

@@ -152,2 +161,4 @@

this.runHooks('beforeDelete', entity);
const query = `db.getCollection('${this.metadata[entity.constructor.name].collection}').deleteOne({ _id: ${entity._id} });`;
this.options.logger(`[query-logger] ${query}`);
const result = await this.getCollection(this.metadata[entity.constructor.name].collection).deleteOne({ _id: entity._id });

@@ -162,2 +173,4 @@ delete this.identityMap[`${entity.constructor.name}-${entity.id}`];

async count(entityName: string, where: any): Promise<number> {
const query = `db.getCollection('${this.metadata[entityName].collection}').count(${JSON.stringify(where)});`;
this.options.logger(`[query-logger] ${query}`);
return this.getCollection(this.metadata[entityName].collection).count(where);

@@ -164,0 +177,0 @@ }

@@ -69,2 +69,3 @@ import 'reflect-metadata';

this.db = this.client.db(this.options.dbName);
this.options.logger(`MikroORM: successfully connected to database ${this.options.dbName} on ${this.options.clientUrl}`);

@@ -71,0 +72,0 @@ return this.db;

@@ -163,4 +163,8 @@ import { Utils } from './Utils';

changeSet.entity.updatedAt = changeSet.payload.updatedAt = new Date();
const query = `db.getCollection('${changeSet.collection}').updateOne({ _id: ${changeSet.entity._id} }, { $set: ${JSON.stringify(changeSet.payload)} });`;
this.em.options.logger(`[query-logger] ${query}`);
await this.em.getCollection(changeSet.collection).updateOne({ _id: changeSet.entity._id }, { $set: changeSet.payload });
} else {
const query = `db.getCollection('${changeSet.collection}').insertOne(${JSON.stringify(changeSet.payload)});`;
this.em.options.logger(`[query-logger] ${query}`);
const result = await this.em.getCollection(changeSet.collection).insertOne(changeSet.payload);

@@ -167,0 +171,0 @@ changeSet.entity._id = result.insertedId;

2

package.json
{
"name": "mikro-orm",
"version": "0.5.6",
"version": "0.6.0",
"description": "Simple typescript mongo ORM for node.js based on data-mapper, unit-of-work and identity-map patterns",

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

@@ -131,3 +131,2 @@ # mikro-orm

- rehydrate and populate missing references when fetching already loaded entities from db
- add query logging
- add nativeUpdate and nativeDelete (without hooks support), allow only entities in EM#remove

@@ -134,0 +133,0 @@ - remove references on other entities when deleting entity (e.g. from M:N collection)

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