import axios from 'axios';
// Assuming the other app is called 'app2'
const LITEFS_ENDPOINT = 'https://app.fly.dev.internal:8080';
async function upsertTable(tableName: string, name: string) {
const query = `INSERT INTO ${tableName}(name) VALUES('${name}') ON CONFLICT(name) DO UPDATE SET name=excluded.name RETURNING id;`;
const response = await axios.post(LITEFS_ENDPOINT, {
query: query,
});
console.log('Reponses below:');
console.log(response.data[0].id);
return response.data[0].id;
}
async function upsertData(job: any) {
const cityId = await upsertTable('city', job.city);
const stateId = await upsertTable('state', job.state);
const countryId = await upsertTable('country', job.country);
const addressQuery = `INSERT INTO address(cityId, stateId, countryId) VALUES(${cityId}, ${stateId}, ${countryId}) ON CONFLICT(cityId, stateId, countryId) DO UPDATE SET cityId=excluded.cityId, stateId=excluded.stateId, countryId=excluded.countryId RETURNING id;`;
const response = await axios.post(LITEFS_ENDPOINT, {
query: addressQuery,
});
console.log(response.data[0].id);
return response.data[0].id;
}
async function go(job: any) {
await upsertData(job);
}
const job = { city: 'New York', state: 'NY', country: 'USA' };
go(job);
I am trying to write to LiteFS from another app. I am getting the error below when running this:
AxiosError: getaddrinfo ENOTFOUND app.fly.dev.internal
I am not sure what the correct way to go about this. I am trying to write from my webscraper to my epic stack app that has the sqlite db. I would think this would work since litefs has a built in proxy Built-in HTTP Proxy · Fly Docs
I’ve seen some blogs and other information say that we should be able to to do some amount of writes and not have issues through this. It’s a webscraper that is not going superfast so it shouldn’t be anything at most at around 10 requests per second to write to the DB. I believe this shouldn’t be an issue?