Skip to content
Back to catalog
Neon

Query Neon Postgres

Store and query rows in a Neon serverless Postgres database from an Appwrite Function

Neon is a serverless Postgres platform. It separates storage from compute, so databases scale with traffic, suspend when idle, and can be branched like code for previews and tests.

How does the integration work?

The Query Neon Postgres function template shows how to work with a Neon database from Appwrite Functions using the postgres driver over TLS. On its first request, the function creates a warehouses table if it doesn't exist. Each GET request then inserts a warehouse with a random location and capacity and returns up to 100 rows as JSON.

The function keeps its connection between executions, so warm requests skip the connection setup. Use it as a starting point for your own SQL queries.

How to implement

To implement the Neon integration, there are several steps you must complete:

Step 1: Create a Neon project

Sign in to the Neon console and create a project. Open the project's connection details and save these values:

ValueExample
Hostep-still-sea-a792sh84.eu-central-1.aws.neon.tech
Databaseneondb
RoleThe database user, for example neondb_owner
PasswordThe role's password
Endpoint IDThe first part of the host, for example ep-still-sea-a792sh84. If the host is a pooled one, leave out the -pooler suffix.

Step 2: Create the Appwrite Function

For this step, you must create an account on Appwrite Cloud or self-host Appwrite if you haven't already. If you self-host Appwrite, enable a Node.js runtime in _APP_FUNCTIONS_RUNTIMES and follow the Functions configuration guide so function domains work.

In the Appwrite Console, go to Functions, open the Templates tab, search for Query Neon Postgres, and click Create from template. Fill in the Template variables:

VariableValue
PGHOSTThe host
PGDATABASEThe database name
PGUSERThe role
PGPASSWORDThe password
ENDPOINT_IDThe endpoint ID

Choose Connect your repository to clone the template into a Git repository where you can write your own queries, or Connect later to deploy it right away. Then click Create and deploy.

Step 3: Test the function

Copy the function's domain from the Domains tab and send a request:

Bash
curl https://<FUNCTION_DOMAIN>

The response lists the rows in the warehouses table:

JSON
[
{ "id": 1, "location": "Street 108, Earth", "capacity": 50 },
{ "id": 2, "location": "Street 675, Earth", "capacity": 70 }
]

Every request adds another row. Requests with other methods return 404. You can inspect the table in the Neon console's SQL editor.

The template allows anyone to execute the function, so anyone who finds its domain can add rows to your database. Before you query your own data, replace Any in the function's execute access with narrower roles, such as Users, and call the function with an Appwrite SDK instead of its domain.

Read more about Neon and Appwrite Functions

If you would like to learn more about Neon and Appwrite Functions, we have some resources that you should visit:

Technology Partner Program

Building on Appwrite?

Teams and developers who ship integrations, tools, or services on Appwrite can join our partner program for verified catalog placement, co-marketing, training, and engineering support.