Javascript 如何避免在AdoniJS中覆盖我的sqlite数据库?
我制作了一个从另一个API加载数据的API,将数据存储在sqlite数据库中。我的路由中有4个参数,在这之后,我的应用程序将检查输入是否在我的数据库中,如果是,则从数据库返回值,如果不是,则从主API返回值。问题是有时,我不知道什么时候,我的数据库会覆盖最后的输入 异步索引({ 要求 响应 }){Javascript 如何避免在AdoniJS中覆盖我的sqlite数据库?,javascript,sql,node.js,sqlite,adonis.js,Javascript,Sql,Node.js,Sqlite,Adonis.js,我制作了一个从另一个API加载数据的API,将数据存储在sqlite数据库中。我的路由中有4个参数,在这之后,我的应用程序将检查输入是否在我的数据库中,如果是,则从数据库返回值,如果不是,则从主API返回值。问题是有时,我不知道什么时候,我的数据库会覆盖最后的输入 异步索引({ 要求 响应 }){ const date=request.input('date'); const hourInput=request.input('hour'); const lat=请求输入('lat'); cons
const date=request.input('date');
const hourInput=request.input('hour');
const lat=请求输入('lat');
const lon=request.input('lon');
const weatherData=等待天气
.query()
.where('lat','=',lat)
.where('long','=',lon)
.where('hour','=',hourInput)
.where('date','=',date)
.fetch()
if(weatherData.rows[0]){
控制台日志(“exista”)
json(weatherData.rows[0].temp_c)
}否则{
试一试{
const history=等待axios.get('http://api.apixu.com/v1/history.json?key=“+WEATHER_KEY+”&q=“+lat+”、“+lon+”&dt=”+日期)
for(设i=0;i
const date = request.input('date');
const hourInput = request.input('hour');
const lat = request.input('lat');
const lon = request.input('lon');
const weatherData = await Weather
.query()
.where('lat', '=', lat)
.where('long', '=', lon)
.where('hour', '=', hourInput)
.where('date', '=', date)
.fetch()
if (weatherData.rows[0]) {
console.log("exista")
response.json(weatherData.rows[0].temp_c)
} else {
try {
const history = await axios.get('http://api.apixu.com/v1/history.json?key=' + WEATHER_KEY + '&q=' + lat + ',' + lon + '&dt=' + date)
for (let i = 0; i <= 23; i++) {
const hour = history.data.forecast.forecastday[0].hour[i].time.slice(11, 13);
if (hourInput === hour) {
const temp = history.data.forecast.forecastday[0].hour[i].temp_c;
weather.lat = lat;
weather.long = lon;
weather.date = date;
weather.hour = hourInput;
weather.temp_c = temp;
await weather.save();
response.json(temp)
console.log("Nu")
}
//response.json(weatherData.rows);
}
} catch (err) {
console.log(err);
//response.status(500).json({})
}
}