Hoverfly Cloud
Visit Our Main SitePricingTry Hoverfly Cloud
  • Introduction
  • Use cases for API Simulation
  • Key concepts
  • What's New
  • Dashboard
  • Simulation
    • Create simulations
    • Configuring Request Matchers
      • JSON Request Matchers on the Body
        • EXACT Matcher
        • JSON Matcher
        • JSON Partial Matcher
        • JSONPath Matcher
        • Regular Expression Matcher
      • Handling the response when Hoverfly cannot match
    • Building a JSON Response
      • Using a JSON object from the Request
      • Looping over a JSON array from the Request
    • Simulating Webhooks and Callbacks
    • Using templating in simulations
      • Render back any part of the Request
      • Render synthetic data
      • Faker functions
      • Render dates and times with offsets
      • Conditional logic
      • Looping over arrays
      • Variables and Arrays
      • Arithmetic operations
      • String operations
      • Validation operations
      • Simulating a persistent backend
      • Transitioning state between requests
      • Combining and nesting templating functions
      • Useful helper functions
      • Avoiding HTML encoding in function return values
    • Using data sources in simulations
      • Querying data sources
      • Updating data in data sources
      • Deleting data from data sources
      • Inserting data into a data source
      • Guidance on using the SQL like syntax
    • Working with Simulation Files
  • Service
    • Start a new service
    • Use a service
    • Update a service
    • Configuring Journal Indexing
  • Command line interface
    • Hoverfly Cloud CLI commands
  • Tutorials
    • Quickstart
    • Creating simulations and services
      • Tutorial 1: Create a service and simulation manually
      • Tutorial 2: Create a service and simulation by importing from a Swagger specification
      • Tutorial 3: Create a service and simulation by capturing real API traffic
    • Response Templating
      • Tutorial 4: Response Templating
    • Hoverfly service modes
      • Tutorial 5: Simulate, Capture, Spy and Passthrough modes
    • Automating with the CLI and API
      • Tutorial 6: Using the CLI and the Hoverfly Cloud API
Powered by GitBook
On this page
  • Deleting data from a CSV Data Source
  • Method 1: Delete data with {{csvDeleteRows}}
  • Method 2: Delete data with {{csvSqlCommand}}
  • s
  1. Simulation
  2. Using data sources in simulations

Deleting data from data sources

Delete CSV data source records on-the-fly within simulations with Hoverfly Cloud Enterprise - data is removed temporarily, reverting on restart.

Deleting data from a CSV Data Source

You can delete data from a CSV data source on the fly within your simulation just as if your API were deleting data from a real data source. The data is removed for the duration that the service is running. When the service is restarted, the data will revert to what was in the original uploaded CSV.

There are two ways to delete data.

  1. Using the {{csvDeleteRows}} function which will delete rows where a specified column matches a specified value

  2. Using the {{csvSqlCommand}} function which allows you to use a SQL like syntax to issue a DELETE SQL command which allows more conditions to be matched than csvDeleteRows.

For illustration we will use this data source called "pets":

id
category
name
status

1000

birds

Archie

available

1001

dogs

Zipper

available

1002

dogs

Teddy

sold

Method 1: Delete data with {{csvDeleteRows}}

This method deletes data where a column matches a value that you specify. It can also optionally return the number of rows deleted into the template, or into another function wrapping it.

Syntax:

{{csvDeleteRows 'data-source-name' 'column-name' 'query-value' output-result}}

Template Example: Delete all birds and don't return the count

{{ csvDeleteRows 'pets' 'category' 'birds' false }}

Result:

In this case there will be no output from csvDeleteRows but the data in memory for all subsequent calls to the API simulation will be modified as follows:

id
category
name
status

1001

dogs

Zipper

available

1002

dogs

Teddy

sold

If the output-result flag had been set to true, then the function would have had the following output:

1

Method 2: Delete data with {{csvSqlCommand}}

Syntax:

{{ csvSqlCommand 'sql-delete-statement' }}

Template Example: Delete all dogs whose ids are greater than 1001

{{ csvSqlCommand "DELETE FROM pets WHERE category = 'dogs' AND id > '1001'" }}

Result:

There is no output from a SQL DELETE statement but the data in memory for all subsequent calls to the API simulation will be modified as follows:

id
category
name
status

1000

birds

Archie

sold

1001

dogs

Zipper

available

s

PreviousUpdating data in data sourcesNextInserting data into a data source

Last updated 4 days ago

A simplified SQL like syntax can be used to delete the data in a csv data source. (This syntax can also be used to and from the data source. You cannot insert using this syntax however there is a mechanism which can be read about .)

You can read more about using this SQL like syntax .

SELECT
UPDATE
here
here