-
Notifications
You must be signed in to change notification settings - Fork 69
Open
Description
First of all, I want to say thanks because I am looking for a library that allows me to write migrations in .js file, and this seems to be the only one available and actively maintained. In fact one of the example from Readme illustrated my use case (pulling data from external sources, something that's not possible by writing .sql).
However, I am concern about large query. What if my data source has hundreds or even thousands of rows? While I can do something like
import axios from "axios";
const largeNumberOfRows = 5000;
module.exports.generateSql = async () => {
let query = '';
for (let i = 0; i < largeNumberOfRows; i++) {
const response = await axios({
method: "get",
url: `https://api.example.org/person/${i}`,
});
query += `INSERT INTO person (name, age) VALUES ('${response.data.name}', ${response.data.age});`
}
return query;
};I am worried about the string being too big and causing OOM, so I would like to be able to execute query in each loop instead of concatenating the string. Generator / Async generator seems to be a good api for such use case.
import axios from "axios";
const largeNumberOfRows = 5000;
module.exports.generateSql = async function* () {
for (let i = 0; i < largeNumberOfRows; i++) {
const response = await axios({
method: "get",
url: `https://api.example.org/person/${i}`,
});
yield `INSERT INTO person (name, age) VALUES ('${response.data.name}', ${response.data.age});`
}
};What do you think?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels