databases
Creates, updates, deletes, gets or lists a databases resource.
Overview
| Name | databases |
| Type | Resource |
| Id | netlify.database.databases |
Fields
The following fields are returned by SELECT queries:
- get
| Name | Datatype | Description |
|---|---|---|
connection_string | string | The connection string for the database |
Methods
The following methods are available for this resource:
| Name | Accessible by | Required Params | Optional Params | Description |
|---|---|---|---|---|
get | select | site_id | role | Returns the database connection string for the specified site. |
create | insert | site_id | Creates a new database for the specified site. If a database already exists, returns the existing connection string. The database region defaults to the site's functions region if not specified. | |
delete | delete | site_id | Deletes the database and all associated branches and snapshots for the specified site. |
Parameters
Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.
| Name | Datatype | Description |
|---|---|---|
site_id | string | |
role | string | The database role to use for the connection string. Defaults to netlifydb_owner if not specified. |
SELECT examples
- get
Returns the database connection string for the specified site.
SELECT
connection_string
FROM netlify.database.databases
WHERE site_id = '{{ site_id }}' -- required
AND role = '{{ role }}'
;
INSERT examples
- create
- Manifest
Creates a new database for the specified site. If a database already exists, returns the existing connection string. The database region defaults to the site's functions region if not specified.
INSERT INTO netlify.database.databases (
region,
site_id
)
SELECT
'{{ region }}',
'{{ site_id }}'
RETURNING
connection_string
;
# Description fields are for documentation purposes
- name: databases
props:
- name: site_id
value: "{{ site_id }}"
description: Required parameter for the databases resource.
- name: region
value: "{{ region }}"
description: |
The region where the database should be created. Defaults to the site's functions region if not specified.
DELETE examples
- delete
Deletes the database and all associated branches and snapshots for the specified site.
DELETE FROM netlify.database.databases
WHERE site_id = '{{ site_id }}' --required
;