public static async void InsertOrUpdate(this DirectDatabaseBase db, DirectModel model) { //if (model.LongID.HasValue) // await Update(db, model); //else // Insert(db, model); }
public static async Task <int?> UpdateAsync(this DirectDatabaseBase db, DirectModel model) { if (!model.LongID.HasValue) { throw new Exception("ID is not set, maybe this table was not loaded"); } // UPDATE MobilePaywall.core.A SET A=1 WHERE AID=1 string command = string.Format("UPDATE {0}.{1}{2} SET {3} WHERE {4}={5};", db.DatabaseName, db.DatabaseSchemeString, model.GetTableName(), model.Snapshot.GetUpdateData(), model.GetIdNameValue(), model.LongID.Value); DirectExecuteResult result = await db.ExecuteAsync(command); if (!result.IsSuccessfull) { return(null); } else { model.OnAfterUpdate?.Invoke(); model.Snapshot.SetSnapshot(); return(result.NumberOfRowsAffected); } }
public static void Delete(this DirectDatabaseBase db, DirectModel model) { string command = string.Format("DELETE FROM {0}.{1}.{2} WHERE {2}ID={3};", db.DatabaseName, db.DatabaseScheme, model.GetTableName(), model.GetID()); db.Execute(command); }
public static string ConstructInsertQuery(this DirectModel model, List <string> avaliableVariables = null) // we use this avaliableVariables in Later load insert from TransactionalManager { model.OnBeforeInsert(); string command = string.Format("INSERT INTO {0}.{1}{2} ({3}) VALUES ({4});", model.GetDatabase().DatabaseName, model.GetDatabase().DatabaseSchemeString, model.GetTableName(), model.Snapshot.GetPropertyNamesForInsert(), model.Snapshot.GetPropertyValuesForInsert(false, avaliableVariables)); return(command); }
public static async Task InsertOrUpdateAsync(this DirectDatabaseBase db, DirectModel model) { if (model.LongID.HasValue) { await UpdateAsync(db, model); } else { await InsertAsync <DirectModel>(db, model); } }
public static void Insert(this DirectDatabaseBase db, DirectModel model) { string command = string.Format("INSERT INTO {0}.{1}.{2} ({3}) VALUES ({4});", db.DatabaseName, db.DatabaseScheme, model.GetTableName(), model.GetPropertyNamesForInsert(), model.GetPropertyValuesForInsert()); int?id = db.Execute(command); if (id.HasValue) { model.SetID(id.Value); } }
public static T Insert <T>(this DirectDatabaseBase db, DirectModel model) where T : DirectModel { DirectExecuteResult result = db.Execute(model.ConstructInsertQuery()); if (result.IsSuccessfull && result.LastID.HasValue) { model.LongID = result.LastID; model.Snapshot.SetSnapshot(); return((T)model); } return((T)model); }
public static void Update(this DirectDatabaseBase db, DirectModel model) { if (model.ID() <= 0) { throw new Exception("ID is not set, maybe this table was not loaded"); } // UPDATE MobilePaywall.core.A SET A=1 WHERE AID=1 string command = string.Format("UPDATE {0}.{1}.{2} SET {3} WHERE {2}ID={4};", db.DatabaseName, db.DatabaseScheme, model.GetTableName(), model.GetUpdateData(), model.GetID()); db.Execute(command); }
public void Load(DirectModel model, string loadQuery) { lock (_queryLoaderLockObj) { if (!this._queryLoader.ContainsKey(model)) { this._queryLoader.Add(model, loadQuery); } } if (this.Count >= this.Limit) { this.RunAsync(); } }
public void Insert(DirectModel model) { lock (_queryInserterLockObj) { if (!this._queryInserter.Contains(model)) { this._queryInserter.Add(model); } } if (this.Count >= this.Limit) { this.RunAsync(); } }
/// /// Insert values /// // SUMMARY: Used to update last change of the model (not multiple times) public void Add(DirectModel model) { lock (_queryModelsLockObj) { if (!this._queryModels.Contains(model)) { this._queryModels.Add(model); } } if (this.Count >= this.Limit) { this.RunAsync(); } }
public static async Task <T> InsertAsync <T>(this DirectDatabaseBase db, DirectModel model) where T : DirectModel { string command = string.Format("INSERT INTO {0}.{1}{2} ({3}) VALUES ({4});", db.DatabaseName, db.DatabaseSchemeString, model.GetTableName(), model.Snapshot.GetPropertyNamesForInsert(), model.Snapshot.GetPropertyValuesForInsert()); DirectExecuteResult result = await db.ExecuteAsync(command); if (result.IsSuccessfull && result.LastID.HasValue) { model.LongID = result.LastID; model.Snapshot.SetSnapshot(); return((T)model); } return((T)model); }
internal static string ConstructUpdateQuery(this DirectModel model) { if (!model.LongID.HasValue) { throw new Exception("ID is not set, maybe this table was not loaded"); } model.OnBeforeUpdate(); // UPDATE MobilePaywall.core.A SET A=1 WHERE AID=1 string command = string.Format("UPDATE {0}.{1}{2} SET {3} WHERE {4}={5};", model.GetDatabase().DatabaseName, model.GetDatabase().DatabaseSchemeString, model.GetTableName(), model.Snapshot.GetUpdateData(), model.GetIdNameValue(), model.LongID.Value); return(command); }
public static List <T> LoadMany <T>(this DirectDatabaseBase db, string whereCommand = "") { T temp = (T)Activator.CreateInstance(typeof(T)); DirectModel model = temp as DirectModel; if (model == null) { throw new Exception("Cast error"); } string command = string.Format("SELECT * FROM {0}.{1}.{2}{3}", db.DatabaseName, db.DatabaseScheme, model.GetTableName(), (!string.IsNullOrEmpty(whereCommand) ? " WHERE " + whereCommand : "")); DirectContainer dc = db.LoadContainer(command); return(dc.ConvertList <T>()); }
public static int?Update(this DirectDatabaseBase db, DirectModel model) { if (!model.LongID.HasValue) { throw new Exception("ID is not set, maybe this table was not loaded"); } DirectExecuteResult result = db.Execute(model.ConstructUpdateQuery()); if (!result.IsSuccessfull) { return(null); } else { model.Snapshot.SetSnapshot(); return(result.NumberOfRowsAffected); } }
public static async Task <bool> DeleteAsync(this DirectDatabaseBase db, DirectModel model) { if (!model.LongID.HasValue) { throw new Exception("THIS model has not ID"); } string command = string.Format("DELETE FROM {0}.{1}{2} WHERE {3}={4};", db.DatabaseName, db.DatabaseSchemeString, model.GetTableName(), model.GetIdNameValue(), model.LongID.Value); DirectExecuteResult result = await db.ExecuteAsync(command); if (result.IsSuccessfull) { model.LongID = null; model.Snapshot.SetSnapshot(); return(true); } return(false); }
public static void InsertLater(this DirectModel model) { model.GetDatabase().TransactionalManager.Add(model.ConstructInsertQuery()); }