@spinajs/orm
Advanced tools
Comparing version 2.0.309 to 2.0.310
@@ -21,8 +21,14 @@ import { ModelData, ModelDataWithRelationData, PartialArray, PickRelations } from './types.js'; | ||
export declare class ModelBase<M = unknown> implements IModelBase { | ||
private __is_dirty__; | ||
/** | ||
* Marks model as dirty. It means that model have unsaved changes | ||
*/ | ||
IsDirty: boolean; | ||
get IsDirty(): boolean; | ||
set IsDirty(val: boolean); | ||
private _container; | ||
/** | ||
* prop to track model props that changeded since last update | ||
*/ | ||
private __dirty_props__; | ||
/** | ||
* List of hidden properties from JSON / dehydrations | ||
@@ -203,3 +209,3 @@ * eg. password field of user | ||
dehydrateWithRelations(omit?: string[]): ModelDataWithRelationData<this>; | ||
toSql(): Partial<this>; | ||
toSql(onlyDirty?: boolean): Partial<this>; | ||
/** | ||
@@ -206,0 +212,0 @@ * deletes enitt from db. If model have SoftDelete decorator, model is marked as deleted |
@@ -27,2 +27,4 @@ "use strict"; | ||
target.IsDirty = true; | ||
// HACK to access private prop ( internal use ) | ||
target.__dirty_props__.push(p); | ||
} | ||
@@ -85,2 +87,14 @@ } | ||
/** | ||
* Marks model as dirty. It means that model have unsaved changes | ||
*/ | ||
get IsDirty() { | ||
return this.__is_dirty__; | ||
} | ||
set IsDirty(val) { | ||
this.__is_dirty__ = val; | ||
if (!val) { | ||
this.__dirty_props__ = []; | ||
} | ||
} | ||
/** | ||
* Gets descriptor for this model. It contains information about relations, orm driver, connection properties, | ||
@@ -307,6 +321,7 @@ * db table attached, column information and others. | ||
constructor(data) { | ||
this.__is_dirty__ = false; | ||
/** | ||
* Marks model as dirty. It means that model have unsaved changes | ||
* prop to track model props that changeded since last update | ||
*/ | ||
this.IsDirty = false; | ||
this.__dirty_props__ = []; | ||
/** | ||
@@ -378,4 +393,8 @@ * List of hidden properties from JSON / dehydrations | ||
} | ||
toSql() { | ||
return this.Container.resolve(interfaces_js_1.ModelToSqlConverter).toSql(this); | ||
toSql(onlyDirty) { | ||
const vals = this.Container.resolve(interfaces_js_1.ModelToSqlConverter).toSql(this); | ||
if (onlyDirty) { | ||
return lodash_1.default.pick(vals, this.__dirty_props__); | ||
} | ||
return vals; | ||
} | ||
@@ -422,3 +441,3 @@ /** | ||
} | ||
result = await query.update(this.toSql()).where(this.PrimaryKeyName, this.PrimaryKeyValue); | ||
result = await query.update(this.toSql(true)).where(this.PrimaryKeyName, this.PrimaryKeyValue); | ||
this.IsDirty = false; | ||
@@ -425,0 +444,0 @@ return result; |
@@ -21,8 +21,14 @@ import { ModelData, ModelDataWithRelationData, PartialArray, PickRelations } from './types.js'; | ||
export declare class ModelBase<M = unknown> implements IModelBase { | ||
private __is_dirty__; | ||
/** | ||
* Marks model as dirty. It means that model have unsaved changes | ||
*/ | ||
IsDirty: boolean; | ||
get IsDirty(): boolean; | ||
set IsDirty(val: boolean); | ||
private _container; | ||
/** | ||
* prop to track model props that changeded since last update | ||
*/ | ||
private __dirty_props__; | ||
/** | ||
* List of hidden properties from JSON / dehydrations | ||
@@ -203,3 +209,3 @@ * eg. password field of user | ||
dehydrateWithRelations(omit?: string[]): ModelDataWithRelationData<this>; | ||
toSql(): Partial<this>; | ||
toSql(onlyDirty?: boolean): Partial<this>; | ||
/** | ||
@@ -206,0 +212,0 @@ * deletes enitt from db. If model have SoftDelete decorator, model is marked as deleted |
@@ -21,2 +21,4 @@ import { SortOrder } from './enums.js'; | ||
target.IsDirty = true; | ||
// HACK to access private prop ( internal use ) | ||
target.__dirty_props__.push(p); | ||
} | ||
@@ -77,2 +79,14 @@ } | ||
/** | ||
* Marks model as dirty. It means that model have unsaved changes | ||
*/ | ||
get IsDirty() { | ||
return this.__is_dirty__; | ||
} | ||
set IsDirty(val) { | ||
this.__is_dirty__ = val; | ||
if (!val) { | ||
this.__dirty_props__ = []; | ||
} | ||
} | ||
/** | ||
* Gets descriptor for this model. It contains information about relations, orm driver, connection properties, | ||
@@ -299,6 +313,7 @@ * db table attached, column information and others. | ||
constructor(data) { | ||
this.__is_dirty__ = false; | ||
/** | ||
* Marks model as dirty. It means that model have unsaved changes | ||
* prop to track model props that changeded since last update | ||
*/ | ||
this.IsDirty = false; | ||
this.__dirty_props__ = []; | ||
/** | ||
@@ -370,4 +385,8 @@ * List of hidden properties from JSON / dehydrations | ||
} | ||
toSql() { | ||
return this.Container.resolve(ModelToSqlConverter).toSql(this); | ||
toSql(onlyDirty) { | ||
const vals = this.Container.resolve(ModelToSqlConverter).toSql(this); | ||
if (onlyDirty) { | ||
return _.pick(vals, this.__dirty_props__); | ||
} | ||
return vals; | ||
} | ||
@@ -414,3 +433,3 @@ /** | ||
} | ||
result = await query.update(this.toSql()).where(this.PrimaryKeyName, this.PrimaryKeyValue); | ||
result = await query.update(this.toSql(true)).where(this.PrimaryKeyName, this.PrimaryKeyValue); | ||
this.IsDirty = false; | ||
@@ -417,0 +436,0 @@ return result; |
{ | ||
"name": "@spinajs/orm", | ||
"version": "2.0.309", | ||
"version": "2.0.310", | ||
"description": "framework orm module", | ||
@@ -58,6 +58,6 @@ "main": "lib/cjs/index.js", | ||
"dependencies": { | ||
"@spinajs/configuration-common": "^2.0.309", | ||
"@spinajs/di": "^2.0.309", | ||
"@spinajs/exceptions": "^2.0.309", | ||
"@spinajs/log-common": "^2.0.309", | ||
"@spinajs/configuration-common": "^2.0.310", | ||
"@spinajs/di": "^2.0.310", | ||
"@spinajs/exceptions": "^2.0.310", | ||
"@spinajs/log-common": "^2.0.310", | ||
"glob": "^8.1.0", | ||
@@ -64,0 +64,0 @@ "glob-to-regexp": "^0.4.1", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1309393
17626