Create and manage databases
Create a database in SQL Database from Azion Console, the Azion API, or the azion library, then list, retrieve, and delete it.
You create a database in SQL Database from Azion Console, the Azion API, or the azion library. The same three interfaces list the databases of your account, retrieve one, and delete one.
A new database carries the name you set and nothing else. For the tables, the rows, and the SQL that reads them, refer to Create tables and query data.
Prerequisites
- SQL Database enabled on your account. The product is in Preview and is not enabled by default, so request access through Technical Support.
- A name for the database, no shorter than 6 characters and no longer than 50, spelled with letters, numbers, and the hyphen. No two databases in one account share a name.
- The Edit SQL Database permission, which grants permission to create and edit databases and their data through the Azion API. View SQL Database grants permission to view them. Refer to Teams Permissions.
- An account that reaches Azion Console, for the three Console procedures. Refer to How to access Azion Console.
- A personal token to authorize the four API requests.
- Node and the
azionpackage, for the library procedures. The library reads your token fromAZION_TOKEN, andAZION_DEBUGturns on request logging. Refer to Azion SQL library.
Create a database using Azion Console
A database is created from the SQL Database page, and the form asks for a name and nothing else. To create the database:
Access Azion Console > SQL Database.
Select the SQL Database create control. The Create Database page opens.
In General, enter a Name of 6 to 50 characters, built from letters, numbers, and the hyphen. Any other character is refused with “Use only letters, numbers and hyphen (-)“.
The database appears in the SQL Database list. Its Status reads creating until the database is ready, which takes roughly 15 seconds.
Create a database using the API
Send a POST request to the databases endpoint. The body accepts name and active, and no other field. To create the database:
The API answers with HTTP 202. The envelope’s state is pending while the database’s own status is creating:
Provisioning takes roughly 15 seconds. Send GET /databases/{database_id} until status reads created.
The database is stored under the integer identifier in data.id, and every other operation takes that identifier in its path. last_modified, last_editor, and product_version are read-only.
Create a database using the azion library
azion/sql runs the same operations from Node and TypeScript. One flat import carries the database functions and the query functions:
The library is not a passthrough on the API’s shapes. It camelCases the record fields to lastModified, lastEditor, and productVersion, and a query it runs returns columns and rows without rows_read, rows_written, or query_duration_ms.
To create the database, pass the name to createDatabase:
The database is created under the name you passed, and it appears in the SQL Database list of your account. data carries the stored record, and error carries a message and the operation that failed.
List your databases
A list is scoped to the account the request authenticates as, and it holds every database that account created.
Azion Console
The SQL Database page of Azion Console lists every database in your account, with the columns Name, Status, Last Editor, and Last Modified. An account that holds no database shows the empty state “No SQL Databases yet”, with the line “Create your first database to store relational data and run SQL queries.”
The API
Send a GET request to the databases endpoint:
The response carries one database object per entry under results, with the page they belong to:
count is how many databases match the request, and total_pages is how many pages they divide into at the current page_size. next and previous hold the adjacent pages, and they are null at either end.
Four query parameters shape the response. page selects the page, and page_size sets how many databases it holds: the default is 10 and the ceiling is 100, above which the endpoint returns HTTP 400 with error 10097, Invalid Page Size. search matches a name partially. ordering takes a field name, prefixed with - for descending order.
The azion library
Pass the same parameters to getDatabases:
data carries the databases of your account. page, page_size, search, and ordering narrow the list, as they do on the API endpoint.
Retrieve a database
A retrieve returns one database and the state it is in. The API finds it by its identifier; the azion library finds it by its name.
Azion Console
Access Azion Console > SQL Database, then select the database in the list. The database view opens with three tabs: Tables, Editor, and Settings.
The API
Send a GET request to the database, with its identifier in the path:
The API answers with HTTP 200 and returns the record under data. This envelope carries no state key, unlike the create response:
status reads created once the database is ready. An identifier the account does not hold returns HTTP 404 with error 10004, Not Found.
The azion library
getDatabase takes the database name, not its identifier:
The call returns the record with its fields camelCased:
A name the account does not hold returns {}, with neither data nor error. Test data before you read a field from it.
Delete a database
A database is deleted by the identity each interface knows: Azion Console by its row, the API and the azion library by its identifier.
Azion Console
Access Azion Console > SQL Database, then select Delete on the row of the database. The action is disabled while the status is creating or deleting.
The row disappears from the SQL Database list.
The API
Send a DELETE request to the database, with its identifier in the path:
The API answers with HTTP 202 and reports that it accepted the request, with no record echoed back:
The API accepts the delete even while the status is still creating. Within seconds, the database returns HTTP 404 with error 10004, Not Found.
The azion library
deleteDatabase takes the database identifier, not its name:
The database is removed from your account, and data carries the state of the request, as the API’s delete envelope does.