Пример #1
0
 public static void Set(string key, string value)
 => ExecuteNonQuery(
     @"INSERT INTO __meta (key, value) VALUES (@key, @value)
             ON CONFLICT(key)
             DO UPDATE SET value=@value",
     ("key", key),
     ("value", value));
Пример #2
0
        public void Delete(Guid id, Type type, IDbConnection connection, IDbTransaction transaction)
        {
            var tableName = GetTableName(type);

            CreateTableIfNotExists(tableName, connection, transaction);

            var text = $@"DELETE FROM [{tableName}] WHERE Id = @id";

            ExecuteNonQuery(connection, transaction, text, ("id", Id2Str(id)));
        }
Пример #3
0
        private static void SaveData(string tableName, Guid id, string data, IDbConnection connection,
                                     IDbTransaction transaction)
        {
            var idStr = Id2Str(id);

            var updateText = $@"UPDATE [{tableName}] SET Data = @data WHERE Id = @id";

            ExecuteNonQuery(connection, transaction, updateText, ("id", idStr), ("data", data));

            var insertOrIgnoreText = $@"INSERT OR IGNORE INTO [{tableName}] (Id, Data) VALUES (@id, @data)";

            ExecuteNonQuery(connection, transaction, insertOrIgnoreText, ("id", idStr), ("data", data));
        }
 protected virtual void OnExecuteNonQuery(string query, string exception)
 {
     ExecuteNonQuery?.Invoke(this, new DataBaseManagerEventArgs()
     {
         Query = query, Exception = exception
     });
 }
Пример #5
0
        public void Set <T>(string collectionName, ExecuteNonQuery <T> executable)
        {
            try
            {
                var collection = db.GetCollection <T>(collectionName);
                executable(collection);
            }
            catch (MongoConnectionClosedException e)
            {
                if (TryLimit < TryCount)
                {
                    return;
                }
                TryCount++;
                PacChatServer.GetServer().Logger.Error(e);
                client = new MongoClient();
                db     = client.GetDatabase(DatabaseName);

                Set <T>(collectionName, executable);
            }
            catch (Exception e)
            {
                PacChatServer.GetServer().Logger.Error(e);
            }
            TryCount = 0;
        }
Пример #6
0
 public static void Create(int userId, Team team)
 => ExecuteNonQuery(
     "INSERT INTO team_members (user_id, team_id) VALUES (@userId, @teamId)",
     ("userId", userId),
     ("teamId", team.Id));
Пример #7
0
 public static void Update(User user)
 => ExecuteNonQuery(
     "UPDATE users SET fullname=@fullname WHERE id=@id",
     ("id", user.Id),
     ("fullname", user.FullName));
Пример #8
0
 public static void Create(User user)
 => ExecuteNonQuery(
     "INSERT INTO users (id, fullname) VALUES (@id, @fullname)",
     ("id", user.Id),
     ("fullname", user.FullName));
Пример #9
0
 public static League Create(int id, string name)
 {
     ExecuteNonQuery("INSERT INTO leagues (id, name) VALUES (@id, @name)", ("id", id), ("name", name));
     return(new League(id, name));
 }
Пример #10
0
 public static void Delete(string key)
 => ExecuteNonQuery(
     "DELETE FROM __meta WHERE key=@key",
     ("key", key));