(Deprecated) Budibase Docs
  • 👋Introduction
  • Quickstart tutorials
    • Build a CRUD app
      • Importing the Vehicles table from a CSV
      • Creating the Service log table from scratch
      • Listing recent Service Logs on the home screen
      • Creating a new Service Log with a modal
    • Build a CRUD app- SQL
      • Connecting to your SQL tables
      • Creating Screens from your SQL tables
      • Using relationships between SQL tables
      • Creating a List screen from scratch, using a SQL table
      • Creating a new log, with a modal
    • Build a CRUD app - REST
      • Adding a REST datasource
      • Creating a query that Lists Issues
      • Using your request to display items in your app
      • Add a “Create Item” request
      • Create a new todo Item, inline
      • Mark todo items as “Done”
      • Finishing Touches
  • Building apps
    • Data
      • Users table
      • Data sources
        • Internal/CSV
        • PostgreSQL and MySQL
        • REST
          • REST Queries
          • REST Bindings Example
          • REST Query Import
          • REST Authentication
          • REST Variables
        • Other sources
      • Data Types
        • Text
        • Number
        • True/False (Boolean)
        • Date/time
        • Options
        • Attachments
          • Example
        • Relationships
          • Example
        • Formula
        • JSON
      • Views
        • Filters
        • Calculations
        • Groups
      • Transformers
    • Design
      • Screens
      • Layouts
      • Components
        • Section
        • Container
        • Data Provider
        • Repeater
        • Table
        • Chart
        • Card
        • Text
        • Button
        • Link
        • Icon
        • Image
        • Embed
      • Forms
        • Form Component
        • Field Groups
        • Fields
      • Bindings
      • Actions
      • App State
      • Conditions
      • App theming (coming soon)
      • Handling Data
        • Search/Filter Data
    • Automate
      • Automation steps
        • Triggers
        • Logic
        • Actions
      • Activating and testing
      • Contextual bindings
    • Admin and management
      • User Management
      • Authentication and SSO
        • OpenID Connect
        • SSO with Auth0
        • SSO with Azure AD
        • SSO with Okta
        • SSO with OneLogin
        • SSO with Google
        • SSO with Keycloak
      • Email
      • Portal
      • User Settings
  • Guides
    • Display user-related data
    • Add search
    • Add filtering
    • Create public & private screens
    • Writing a custom SQL query
    • Create a child record from the parent
    • Items assigned to me
    • Master-detail
  • Self-hosting
    • Get started
      • Budibase CLI Setup
    • Hosting methods
      • Overview
      • DigitalOcean
      • Kubernetes (K8S)
      • Docker compose
    • Hosting settings
      • Advanced options
        • Reverse proxy
    • Accessing CouchDB
    • Accessing MinIO
  • References
    • Budibase architecture
    • Deployment information
    • Troubleshooting
    • Contributing to Budibase
      • Writing Your Own External Data Connectors
Powered by GitBook
On this page
Export as PDF
  1. Guides

Writing a custom SQL query

How to create a custom SQL query that accepts parameters from your app’s front end.

PreviousCreate public & private screensNextCreate a child record from the parent

Last updated 3 years ago

This guide will show you how to create a custom SQL query that accepts parameters from your app’s front end.

First, we will setup our query, with parameters. You can see my query below

1. Give your query a name, and ensure it’s a Read function.

2. I’m writing a query with a date range filter, so I need to add 2 parameters: startDate and endDate

3. Be sure to enter some default values for your parameters, so that you can test the query below. 4. Write your query.

5. Use your parameters inside your query. You will need to format your date, depending on how your SQL database expects it. I am using postgres, so need to format my date in the year-month-day format: {{ date startDate “YYYY-MM-DD” }}

Now, we will set up our app to run this query. I first setup my screen with the necessary components:

  • A Form, containing everything.

  • A From date picker, with its “Field” property set to startDate.

  • A To date picker, with its “Field” property set to endDate.

  • A Data Provider, linked to my custom query.

  • A table, underneath the data provider.

Now, we need to apply the values from our date pickers, to our Data Provider.

Click the settings button, beside the Data field:

This will display a drawer, from which we can supply parameters to our query. Beside each parameter, click the ⚡ button to select your date pickers' values. They should look like {{ Form.Fields.startDate }}.

Click save, and test your application!