public async Task <IResponse> searchRecords(string q, int maxResults) { try { using (QueryResult queryResult = await _rqliteService.QueryAsync($"SELECT domain_id,name,type,content,ttl,disabled,auth FROM records WHERE LOWER(name) LIKE '{q.ToLower().Replace("*", "%")}'", ReadConsistencyLevel.None)) { var response = LookupResponse.FromValues(queryResult.Results.FirstOrDefault().Values); if (response != null && response.result.Count > maxResults) { response.result = response.result.Take(maxResults).ToList(); } return(response); } } catch (NoValuesException) { _logger.LogDebug($"No record found for {q}"); return(new BoolResponse { result = false }); } catch (Exception ex) { _logger.LogError(ex.Message); return(new BoolResponse { Log = new List <string>() { $"Failed to search for {q}" }, result = false }); } }
public async Task <IResponse> Lookup(string qname, string qtype) { string query; try { bool removeTrailingDot = _configRoot.GetValue <bool>("RemoveTrailingDot"); if (removeTrailingDot && qname.EndsWith(".")) { qname = qname.Remove(qname.Length - 1); } // We need to ask Transaction Manager if we need to hook the lookup query if (_transactionManager.Transactions().Any() && _transactionManager.TransactionExistsWith(qname, qtype)) { _logger.LogInformation($"Found existing Transaction which handles {qname} {qtype} => Hooking this query with Transaction Manager"); // returns null when last transaction for this record was DELETE else it returns the record itself IRecord transactionRecord = _transactionManager.GetLastTransactionRecord(qname, qtype); if (transactionRecord is null) { _logger.LogInformation("Transaction Manager returned NULL => Record was deleted in Transaction => returning false"); throw new NoValuesException(); } else { _logger.LogInformation("Transaction Manager recturned a record => Record was inserted / updated in transaction => returning record"); _logger.LogDebug(transactionRecord.ToString()); return(new LookupResponse() { result = new List <IRecord>() { transactionRecord } }); } } if (qtype == "ANY") { query = $"SELECT domain_id,name,type,content,ttl,disabled,auth FROM records WHERE LOWER(name)='{qname.ToLower()}'"; } else { query = $"SELECT domain_id,name,type,content,ttl,disabled,auth FROM records WHERE LOWER(name)='{qname.ToLower()}' AND type='{qtype}'"; } using (QueryResult queryResult = await _rqliteService.QueryAsync(query, ReadConsistencyLevel.None)) { return(LookupResponse.FromValues(queryResult.Results.FirstOrDefault().Values)); } } catch (NoValuesException) { _logger.LogDebug($"No record found for {qname}|{qtype}"); return(new BoolResponse { result = false }); } catch (Exception ex) { _logger.LogError(ex.Message); return(new BoolResponse { Log = new List <string>() { $"Failed to lookup {qname}|{qtype}" }, result = false }); } }