Connect your app to ClickHouse
You can connect your Lovable app to a ClickHouse database to run SQL queries and build analytics features. This connection works for both self-hosted and cloud ClickHouse databases using their HTTP interface.
Anyone building an app that needs to read data from a ClickHouse database will need this.
Do this, in order
- 1
Go to the 'Connectors' section in Lovable and select 'ClickHouse'.
This is where you manage all your connections to external services.
- 2
Click 'Add connection'.
This starts the process of setting up a new link to your ClickHouse database.
- 3
Give your connection a clear name, like 'ClickHouse Production' or 'ClickHouse read-only'.
A good name helps you identify this specific connection later, especially if you have multiple.
- 4
Enter the full HTTPS URL of your ClickHouse HTTP interface (including the port), the username, and the password for your ClickHouse user.
These details allow Lovable to securely access your ClickHouse database. If your ClickHouse database doesn't require authentication, you can leave the username and password blank.
- 5
Decide who can use this connection. By default, it's private to you. You can share it with specific workspace members or your entire workspace.
This controls who in your team can build apps using this ClickHouse connection.
- 6
Click 'Connect'.
Lovable will test the connection to make sure it can successfully communicate with your ClickHouse database.
Paste this into your project
Connect my Lovable app to ClickHouse. I need to run SQL queries against my ClickHouse database over the HTTP interface. I have the HTTPS URL, username, and password for a read-only ClickHouse user. I want to share this connection with my entire workspace.
Words decoded
- HTTP interface
- This is a standard way for computer programs to talk to each other over the internet, using web addresses (URLs) and common web methods. ClickHouse uses this to let other apps send it commands and receive data.
- SQL queries
- These are specific commands written in a language called SQL that you use to ask a database for information, like 'show me all customers' or 'count how many sales happened today'.
- Schema
- This is like the blueprint or structure of your database, showing what tables exist, what columns are in each table, and what kind of data each column holds (e.g., numbers, text, dates).
- Self-hosted
- This means you are running the ClickHouse database software on your own computers or servers, rather than using a service provided by ClickHouse itself.
- ClickHouse Cloud
- This is a version of ClickHouse that is hosted and managed by the ClickHouse company, so you don't have to set up or maintain the servers yourself.
- HTTP basic auth
- A simple way to log in to a website or service by sending a username and password with each request.
- Gateway
- In this context, it's a secure middleman service that handles the connection details (like your database username and password) so your app doesn't directly see or send them.
- Paginate
- This means breaking up a very long list of results into smaller, more manageable pages, like how search engine results are shown page by page.
- LIMIT / OFFSET
- These are special commands in SQL that help you paginate. 'LIMIT' says how many results to show, and 'OFFSET' says where to start counting from in the full list.
Where people get stuck
- Using a ClickHouse user with too many permissions; it's recommended to create a dedicated read-only user with access only to the necessary databases and tables.
- Forgetting to include the port number in the HTTP Interface URL.
- Not qualifying table names with the database (e.g., `mydb.users`) because there's no default database.
- Expecting real-time updates without explicitly refreshing, as queries are synchronous and don't automatically poll for new data.
The short version, steps, decoder and prompt on this page are written automatically from Lovable's own documentation and can lag or misread it. The official page is always the authority.