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

Manipulate csv contents #1143

Merged
merged 1 commit into from
Aug 22, 2024
Merged

Conversation

stuioco
Copy link
Contributor

@stuioco stuioco commented Aug 19, 2024

Added 3 templating functions to manipulate csv content.

  • csvCountRows - returns the number of rows in the data source
  • csvDeleteRows - deletes rows with a matching provided field value
  • csvAddRow - adds a new row from a provided array

Docs are also updated

@stuioco stuioco requested a review from tommysitu August 19, 2024 14:49
Copy link
Member

@tommysitu tommysitu left a comment

Choose a reason for hiding this comment

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

Could you explain what the use case would be please? Templating function is not supposed for mutating hoverfly data, their main purpose is to generate dynamic response data.

@stuioco
Copy link
Contributor Author

stuioco commented Aug 20, 2024

Hi Tommy, the main reason to extend the csv capability from read only to read/write is that it gives a much simpler and more natural mechanism to simulate structured data persistence between calls than having to use journal indexing which can be confusing for complex processes.

@kapishmalik
Copy link
Collaborator

It is quite unconventional to do so. We can make another api call to add or delete the data instead of displaying it using template function.

@stuioco
Copy link
Contributor Author

stuioco commented Aug 20, 2024

I agree it's unconventional, but not necessarily a bad idea. I'm struggling to see how using just api calls we can implement a sandbox environment that needs to simulate a mutable persistent back-end that supports CRUD operations on known data structures.

@kapishmalik
Copy link
Collaborator

Can't we write middleware to update CSV and it shows that data instead of templating function. Can you help us understand your use case?

Copy link
Member

@tommysitu tommysitu left a comment

Choose a reason for hiding this comment

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

A small extension for csv templating functions only, with no other functional changes. It offers a simple way to manipulate CSV data sources in the templated response, worth considering for some CSV data source users.

@tommysitu tommysitu merged commit f840dbd into SpectoLabs:master Aug 22, 2024
3 checks passed
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.

3 participants