我在 crate 数据库中有 10k 行数据。如何在不迭代的情况下读取数据。我正在为我的服务使用 crateDB C# Npgsql 客户端。
var connString = "Host=myserver;Username=mylogin;Password=mypass;Database=mydatabase";
await using var conn = new NpgsqlConnection(connString);
await conn.OpenAsync();
// Retrieve all rows
var cmd = new NpgsqlCommand("select * from sensordata where timestamp >= extract(epoch from (now() - interval '1 week'))", conn);
var result = new List<SensorDataViewModel>();
using (var reader = cmd.ExecuteReader())
{
while(reader.HasRows && reader.Read())
{
SensorDataViewModel item = new SensorDataViewModel {
sensorid = reader["sensorid"].ToString(),
deviceid = reader["deviceid"].ToString(),
reading = Convert.ToInt32(reader["reading"]),
timestamp = (double)reader["timestamp"]
};
result.Add(item);
}
}
在这里,我在 while 循环中一次读取每一行。这需要很多时间来处理?