/* Copyright (c) 2020, 2023, The Unified Company. This code is part of Unify. This program is free software; you can redistribute it and/or modify it under the terms of the ESA Software Community License - Strong Copyleft LICENSE, as published by the ESA. See the ESA Software Community License - Strong Copyleft LICENSE, for more details. https://unifyjs.org */ import cacheManager from './cacheManager.js'; class databaseSerializer{ cache = new cacheManager(); setID( row, targetObject ) { if( row.id && targetObject ) { targetObject.id = row.id; } else { targetObject.id = row.id; } } setJoinID( row, targetObject ) { if( row.join_id && targetObject ) { targetObject.join_id = row.join_id; } } copyValue( row, child, value ) { if( value == "true" ) { value = true; } if( value == "false" ) { value = false; } child.value = value; } getChildTable( children, row, child, propertyName ) { var id = row[ propertyName + "_id" ]; //if( id ) { row = this.cache.getObject( child, id ); //} } copyChild( children, child, row ) { var propertyName = child.propertyName; var value = row[ propertyName ]; if( child.datatype && value != null ) { this.copyValue( row, child, value ); } if( child.type == "table" ) { this.getChildTable( children, row, child, propertyName ); } } copyProperties( row, targetObject ) { var children = targetObject.getChildren( ); for( var c = 0; c < children.length; c++ ) { var child = children[ c ]; this.copyChild( children, child, row ); } } serialize( row, targetObject, client ) { this.setID( row, targetObject ); this.setJoinID( row, targetObject ); this.copyProperties( row, targetObject ); } } export default new databaseSerializer();