Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure that Iterator and Readable work correctly for INSERT #844

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

BobdenOs
Copy link
Contributor

Currently a lot of the cds-dbs logic relies on non consuming Arrays which are required to be kept fully in memory. It should be allowed to INSERT any kind of Iterator for scenarios where it is possible to not load the whole dataset into the application.

Examples:

const { Books } = cds.entities

// Generator
const gen = function*(amount) {
  for(let i = 0; i < amount; i++) {
    yield { ID: cds.utils.uuid() }
  }
}
await INSERT(gen(100)).into(Books)

// Generator (async)
const genAsync = async function*(amount) {
  for(let i = 0; i < amount; i++) {
    yield { ID: await fetchKey() }
  }
}
await INSERT(genAsync(100)).into(Books)

// Readable (raw)
express.post('/upload', async (req,res) => {
  await INSERT(req).into(Books)
  res.end('done')
})

// Readable (object)
await INSERT(Readble.from(genAsync(100))).into(Books)

Copy link
Contributor

@danjoa danjoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 love that (assuming it's correct, didn't check in detail :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants