Skip to content

Commit

Permalink
Record.equals
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed May 13, 2024
1 parent 838caf1 commit 5c036fa
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/db/Record.hx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,37 @@ class Record {
return sb.toString();
}

public function equals(other:Record) {
var thisFieldNames = this.fieldNames;
var otherFieldNames = other.fieldNames;
if (thisFieldNames.length != otherFieldNames.length) {
return false;
}

var thisData = this.data;
var otherData = other.data;

for (thisFieldName in thisFieldNames) {
if (!otherData.exists(thisFieldName)) {
return false;
}
}

for (otherFieldName in otherFieldNames) {
if (!thisData.exists(otherFieldName)) {
return false;
}
}

for (thisFieldName in thisFieldNames) {
if (thisData.get(thisFieldName) != otherData.get(thisFieldName)) {
return false;
}
}

return true;
}

public static function fromDynamic(data:Dynamic):Record {
var r = new Record();
for (f in Reflect.fields(data)) {
Expand Down

0 comments on commit 5c036fa

Please sign in to comment.