Skip to content

Commit

Permalink
Fix missing Firebase Async, issue #695
Browse files Browse the repository at this point in the history
TODO: All of these need race love in V2, complete re-vamp.
  • Loading branch information
NickCraver committed Feb 9, 2017
1 parent 7d49507 commit a7ff0b3
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Dapper.Contrib/SqlMapperExtensions.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,4 +429,26 @@ public async Task<int> InsertAsync(IDbConnection connection, IDbTransaction tran
return id;
}
}

public partial class FbAdapter
{
public async Task<int> InsertAsync(IDbConnection connection, IDbTransaction transaction, int? commandTimeout, string tableName, string columnList, string parameterList, IEnumerable<PropertyInfo> keyProperties, object entityToInsert)
{
var cmd = $"insert into {tableName} ({columnList}) values ({parameterList})";
await connection.ExecuteAsync(cmd, entityToInsert, transaction, commandTimeout);

var propertyInfos = keyProperties as PropertyInfo[] ?? keyProperties.ToArray();
var keyName = propertyInfos.First().Name;
var r = await connection.QueryAsync($"SELECT FIRST 1 {keyName} ID FROM {tableName} ORDER BY {keyName} DESC", transaction: transaction, commandTimeout: commandTimeout);

var id = r.First().ID;
if (id == null) return 0;
if (!propertyInfos.Any()) return Convert.ToInt32(id);

var idp = propertyInfos.First();
idp.SetValue(entityToInsert, Convert.ChangeType(id, idp.PropertyType), null);

return Convert.ToInt32(id);
}
}
#endif

0 comments on commit a7ff0b3

Please sign in to comment.