public void DeleteBy(Predicate <TEntity> match) { if (TryFindBy(match, out TEntity e)) { EntityList.Remove(e); return; } ExDebug.LogWarning("Not found Entity"); }
/// <summary> /// Load from local. and initialize database instace. /// </summary> /// <param name="database"></param> /// <param name="filePath"></param> public static void Load(this IDatabase database, string filePath) { if (string.IsNullOrEmpty(filePath)) { ExDebug.LogWarning($"File path is null or empty. Database name is {database.KName}"); return; } database.FromJson(ExIO.ReadAllText(filePath)); }
public virtual void Insert(TEntity entity) { if (entity == null) { ExDebug.LogError($"{typeof(TEntity).Name} is null."); return; } lock (lockObject) { EntityList.Add(entity); } }
public void LogAllEntity() { if (IsNullOrEmpty()) { ExDebug.LogWarning($"{KName} data is null or empty."); return; } foreach (var entity in FindAll()) { ExDebug.Log(entity.ToString()); } }
bool TryFindByKey(string key, out ExtraPlayerPrefEntity entity) { entity = null; if (string.IsNullOrEmpty(key)) { ExDebug.LogError("key is null or empty."); return(false); } entity = EntityList.Find(x => x.Key == key); return(entity != null); }
// Start is called before the first frame update void Start() { // DatabaseSettings.Location.FolderName = "AppDatabase"; // DatabaseSettings.Location.RootFolderPath = Application.dataPath; // // MasterCharacterEntity knight = new MasterCharacterEntity(1, "Knight", "Knight Desc", CharacterType.Knight, DateTime.Now); // MasterCharacterEntity magician = new MasterCharacterEntity(1, "Magician", "Magician Desc", CharacterType.Magician, DateTime.Now); // MasterCharacterEntity monster = new MasterCharacterEntity(1, "Monster", "Monster Desc", CharacterType.Monster, DateTime.Now); // MasterCharacterRepository.Instance.InsertAll(knight, magician, monster); // MasterCharacterRepository.Instance.Save(); // MasterCharacterRepository.Instance.Load(); // MasterCharacterRepository.Instance.LogAllEntity(); // // UserEntity user = new UserEntity(1, "ABCDE"); // UserDataMapper.Instance.Update(user); // UserDataMapper.Instance.Save(); // UserDataMapper.Instance.Load(); // if (UserDataMapper.Instance.TryGet(out user)) { // Debug.Log(user.ToString()); // } var mc = new MasterJobEntity() { Age = 99, FirstName = "hoge", LastName = "huga", }; byte[] bytes = MessagePackSerializer.Serialize(mc); MasterJobEntity entity = MessagePackSerializer.Deserialize <MasterJobEntity>(bytes); ExDebug.Log(entity.FirstName); var json = MessagePackSerializer.ConvertToJson(bytes); ExDebug.Log(json); }
/// <summary> /// Convert to csharp type name. /// </summary> /// <returns>type</returns> /// <param name="dbTypeName">type name on database.</param> /// <param name="unsigned">unsinged is true</param> public static DataType ConvertToCSharpTypeName(string dbTypeName, bool unsigned) { string dbTypeNameToLower = dbTypeName.ToLower(); switch (dbTypeNameToLower) { // -128 to 127 case "tinyint": // -32768 to 32767 case "smallint": case "short": // -2147483648 to 2147483647 case "integer": // -8388608 to 8388607 case "mediumint": { // if (unsigned) { // return "uint"; // } return(DataType.Int); } // -9223372036854775808 to 9223372036854775807 case "bigint": case "long": { // if (unsigned) { // return "ulong"; // } return(DataType.Long); } // -9,223,372,036,854,775,808~9,223,372,036,854,775,807 case "float": { return(DataType.Float); } // -3.402823466E+38~-1.175494351E-38 case "double": { return(DataType.Double); } // true/false, 1/0 case "boolean": case "bool": { return(DataType.Bool); } // 4 case "varchar(4)": // 16 case "varchar(16)": // 32 case "varchar(32)": // 64 case "varchar(64)": // 100 case "varchar(100)": // 128 case "varchar(128)": // 256 case "varchar(256)": // 512 case "varchar(512)": // 1024 case "varchar(1024)": // 2048 case "varchar(2048)": case "string": case "json": case "jsonarray": return(DataType.String); // 1970-01-01 00:00:01' UTC ~ '2038-01-19 03:14:07' UTC case "timestamp": case "datetime": { return(DataType.DateTime); } } ExDebug.LogError($"Undefined [{dbTypeName}] type has been detected."); return(DataType.Undefined); }