Skip to main content

databases

Creates, updates, deletes, gets or lists a databases resource.

Overview

Namedatabases
TypeResource
Idnetlify.database.databases

Fields

The following fields are returned by SELECT queries:

NameDatatypeDescription
connection_stringstringThe connection string for the database

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectsite_idroleReturns the database connection string for the specified site.
createinsertsite_idCreates 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.
deletedeletesite_idDeletes 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.

NameDatatypeDescription
site_idstring
rolestringThe database role to use for the connection string. Defaults to netlifydb_owner if not specified.

SELECT examples

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

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
;

DELETE examples

Deletes the database and all associated branches and snapshots for the specified site.

DELETE FROM netlify.database.databases
WHERE site_id = '{{ site_id }}' --required
;