internal static string ConstructUpdateUpdatedQuery(this DirectModel model) { if (model.IntegerPrimary && !model.ID.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 updatedPropName = string.Empty; foreach (var prop in model.Snapshot.PropertySignatures) { if (prop.Name.ToLower().Equals("updated")) { updatedPropName = prop.Name; } } if (string.IsNullOrEmpty(updatedPropName)) { return(string.Empty); } string command = string.Format(DirectModelHelper.GetDatabase(model).QueryConstructUpdateUpdatedQuery, model.GetTableName(), updatedPropName, model.GetDatabase().ConstructDateTimeParam(DateTime.Now), model.GetIdNameValue(), (model.IntegerPrimary ? model.ID.Value.ToString() : string.Format("'{0}'", model.GetStringID()))); return(command); }
public static async Task <int?> UpdateAsync(this DirectDatabaseBase db, DirectModel model) { if (model.IntegerPrimary && !model.ID.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(DirectModelHelper.GetDatabase(model).QueryConstructUpdateQuery, model.GetTableName(), model.Snapshot.GetUpdateData(), model.GetIdNameValue(), (model.IntegerPrimary ? model.ID.Value.ToString() : string.Format("'{0}'", model.GetStringID()))); DirectExecuteResult result = await db.ExecuteAsync(command); if (!result.IsSuccessfull) { return(null); } else { model.Snapshot.SetSnapshot(); return(result.NumberOfRowsAffected); } }
public static void InsertOrUpdate(this DirectDatabaseBase db, DirectModel model) { //if (model.LongID.HasValue) // Update(db, model); //else // Insert(db, model); }
internal static string ConstructUpdateQuery(this DirectModel model) { if (model.IntegerPrimary && !model.ID.HasValue) { throw new Exception("ID is not set, maybe this table was not loaded"); } model.OnBeforeUpdate(); string updateData = model.Snapshot.GetUpdateData(); if (string.IsNullOrEmpty(updateData)) { return(string.Empty); } // UPDATE MobilePaywall.core.A SET A=1 WHERE AID=1 string command = string.Format(DirectModelHelper.GetDatabase(model).QueryConstructUpdateQuery, model.GetTableName(), model.Snapshot.GetUpdateData(), model.GetIdNameValue(), (model.IntegerPrimary ? model.ID.Value.ToString() : string.Format("'{0}'", model.GetStringID()))); return(command); }
internal static string ConstructInsertQuery(this DirectModel model) { model.OnBeforeInsert(); string command = string.Format(DirectModelHelper.GetDatabase(model).QueryConstructInsertQuery, model.GetTableName(), model.Snapshot.GetPropertyNamesForInsert(), model.Snapshot.GetPropertyValuesForInsert()); return(command); }
public static async Task InsertOrUpdateAsync(this DirectDatabaseBase db, DirectModel model) { if (model.IntegerPrimary && model.ID.HasValue) { await UpdateAsync(db, model); } else { await InsertAsync <DirectModel>(db, model); } }
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.ID = (int)result.LastID; model.Snapshot.SetSnapshot(); return((T)model); } return((T)model); }
public static async Task <T> InsertAsync <T>(this DirectDatabaseBase db, DirectModel model) where T : DirectModel { string command = string.Format(DirectModelHelper.GetDatabase(model).QueryConstructInsertQuery, model.GetTableName(), model.Snapshot.GetPropertyNamesForInsert(), model.Snapshot.GetPropertyValuesForInsert()); DirectExecuteResult result = await db.ExecuteAsync(command); if (result.IsSuccessfull && result.LastID.HasValue) { model.ID = (int)result.LastID; model.Snapshot.SetSnapshot(); return((T)model); } return((T)model); }
public void Load(DirectModel model, string loadQuery) { lock (LockObj) { if (!this._queryLoader.ContainsKey(model)) { this._queryLoader.Add(model, loadQuery); } if (this.Count >= this.Limit) { this.RunAsync(); } } }
public void Insert(DirectModel model) { lock (LockObj) { if (!this._queryInserter.Contains(model) && !this._queryModels.Contains(model)) { this._queryInserter.Add(model); } if (this.Count >= this.Limit) { this.RunAsync(); } } }
private static DirectDatabaseBase GetDatabase(DirectModel model) { if (model.GetDatabase() != null) { return(model.GetDatabase()); } switch (model.DatabaseType) { case DirectDatabaseType.MySQL: return(new Direct.Types.Mysql.DirectDatabaseMysql(string.Empty, string.Empty)); case DirectDatabaseType.SQLite: return(new Direct.Types.SQLite.DirectDatabaseSqlLite(string.Empty, string.Empty)); default: return(null); } }
public static int?Update(this DirectDatabaseBase db, DirectModel model) { if (model.IntegerPrimary && !model.ID.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.IntegerPrimary && !model.ID.HasValue) { throw new Exception("THIS model has not ID"); } string command = string.Format(DirectModelHelper.GetDatabase(model).QueryDelete, model.GetTableName(), model.GetIdNameValue(), (model.IntegerPrimary ? model.ID.Value.ToString() : string.Format("'{0}'", model.GetStringID()))); DirectExecuteResult result = await db.ExecuteAsync(command); if (result.IsSuccessfull) { model.ID = null; model.Snapshot.SetSnapshot(); return(true); } return(false); }
public static void UpdateValue(this DirectModelPropertySignature snap, DirectModel model, JToken value) { if (snap.PropertyInfo.PropertyType == typeof(string)) { snap.PropertyInfo.SetValue(model, value.ToString()); } else if (snap.PropertyInfo.PropertyType == typeof(int) || snap.PropertyInfo.PropertyType == typeof(int?)) { snap.PropertyInfo.SetValue(model, (int)value); } else if (snap.PropertyInfo.PropertyType == typeof(uint) || snap.PropertyInfo.PropertyType == typeof(uint?)) { snap.PropertyInfo.SetValue(model, (uint)value); } else if (snap.PropertyInfo.PropertyType == typeof(DateTime) || snap.PropertyInfo.PropertyType == typeof(DateTime?)) { snap.PropertyInfo.SetValue(model, (DateTime)value); } else if (snap.PropertyInfo.PropertyType == typeof(double) || snap.PropertyInfo.PropertyType == typeof(double?)) { snap.PropertyInfo.SetValue(model, (double)value); } else if (snap.PropertyInfo.PropertyType == typeof(bool) || snap.PropertyInfo.PropertyType == typeof(bool?)) { snap.PropertyInfo.SetValue(model, (bool)value); } }
public static void InsertLater(this DirectModel model) { model.GetDatabase().TransactionalManager.Add(model.ConstructInsertQuery()); }
public BulkModel(DirectModel directModel, int priority = 1) { this.Priority = priority; this.Model = directModel; }