public async Task <List <BackupFolder> > GetFolders(long?parentId = null) { string sql; IEnumerable <SQLiteParameter> parameters; if (parentId.HasValue) { sql = @" SELECT id, name FROM folders WHERE parent_id = @parentId ORDER BY name; "; parameters = GenerateUtils.ConcatParams(DbHelper.GetParam("@parentId", parentId)); } else { sql = @" SELECT id, name FROM folders WHERE parent_id IS NULL OR parent_id = 0 ORDER BY name; "; parameters = null; } SQLiteConnection connection = await GetConnection(Path); try { DbDataReader reader = await connection.ExecuteReaderAsync(sql, parameters); int idIndex = reader.GetOrdinal("id"); int nameIndex = reader.GetOrdinal("name"); List <BackupFolder> nodes = new List <BackupFolder>(); while (await reader.ReadAsync()) { long id = reader.GetInt64(idIndex); string name = reader.GetString(nameIndex); nodes.Add(new BackupFolder(id, name, this)); } return(nodes); } finally { ReleaseConnection(); } }
public async Task <List <BackupFile> > GetFiles(long?folderId) { const string sql = @" SELECT ff.file_name as fileName, f.hash, f.file_name as backupFileName FROM folders_files ff JOIN files f on ff.file_id = f.id WHERE folder_id = @folderId ORDER BY ff.file_name; "; IEnumerable <SQLiteParameter> parameters = GenerateUtils.ConcatParams(DbHelper.GetParam("@folderId", folderId)); SQLiteConnection connection = await GetConnection(Path); try { DbDataReader reader = await connection.ExecuteReaderAsync(sql, parameters); int nameIndex = reader.GetOrdinal("fileName"); int hashIndex = reader.GetOrdinal("hash"); int backupNameIndex = reader.GetOrdinal("backupFileName"); List <BackupFile> nodes = new List <BackupFile>(); while (await reader.ReadAsync()) { string name = reader.GetString(nameIndex); string hash = reader.GetString(hashIndex); string backupFileName = reader.GetString(backupNameIndex); nodes.Add(new BackupFile(name, backupFileName, hash)); } return(nodes); } finally { ReleaseConnection(); } }