create method
Creates a new entity with the given OID into the database. *
-
data
- the content of the entity to store.
Implementation
@override
Future create(Entity entity, Map data) async {
final sql = StringBuffer('insert into "')
..write(entity.otype)..write('"("oid"'),
param = StringBuffer(" values(@oid");
for (final fd in data.keys) {
if (fd == fdOtype || fd == fdOid || data[fd] == null)
continue;
sql..write(',"')..write(fd)..write('"');
param..write(',@')..write(fd);
final dbType = entity.getDBType(fd);
if (dbType?.isNotEmpty ?? false) param..write(':')..write(dbType);
}
sql.write(')');
param.write(')');
data[fdOid] = entity.oid;
var sqlStatement = sql.toString() + param.toString();
if (entity is SqlFlavor) {
final flavor = (entity as SqlFlavor).insertFlavor;
if (flavor != null) sqlStatement = flavor(sqlStatement, data);
}
await access.execute(sqlStatement, data);
_cache?.put(entity); //update cache
}