Appwrite uses tables as containers of rows. Each tables contains many rows identical in structure. The terms tables and rows are used because the Appwrite JSON REST API resembles the API of a traditional NoSQL database, making it intuitive and user-friendly, even though Appwrite uses SQL under the hood.
That said, Appwrite is designed to support both SQL and NoSQL database adapters like MariaDB, MySQL, or MongoDB in future versions.
Create table
You can create tables using the Appwrite Console, a Server SDK, or using the CLI.
You can create a table by heading to the Databases page, navigate to a database, and click Create table.
You can also create tables programmatically using a Server SDK. Appwrite Server SDKs require an API key.
You can also configure permissions in the createTable
method, learn more about the createTable
in the API references.
Before proceeding
Ensure you install the CLI, log in to your Appwrite account, and initialize your Appwrite project.
To create your table using the CLI, first use the appwrite init tables
command to initialize your table.
appwrite init tables
Then push your table using the appwrite push tables
command.
appwrite push tables
This will create your table in the Console with all of your appwrite.json
configurations.
Learn more about the CLI tables commands
Permissions
Appwrite uses permissions to control data access. For security, only users that are granted permissions can access a resource. This helps prevent accidental data leaks by forcing you to make more conscious decisions around permissions.
By default, Appwrite doesn't grant permissions to any users when a new table is created. This means users can't create new rows or read, update, and delete existing rows.
Learn about configuring permissions.
Columns
All rows in a table follow the same structure. Columns are used to define the structure of your rows and help the Appwrite's API validate your users' input. Add your first column by clicking the Add column button.
You can choose between the following types.
Column | Description |
string | String column. |
integer | Integer column. |
float | Float column. |
boolean | Boolean column. |
datetime | Datetime column formatted as an ISO 8601 string. |
enum | Enum column. |
ip | IP address column for IPv4 and IPv6. |
email | Email address column. |
url | URL column. |
relationship | Relationship column relates one table to another. Learn more about relationships. |
If an column must be populated in all rows, set it as required
. If not, you may optionally set a default value. Additionally, decide if the column should be a single value or an array of values.
If needed, you can change an column's key, default value, size (for strings), and whether it is required or not after creation.
You can increase a string column's size without any restrictions. When decreasing size, you must ensure that your existing data is less than or equal to the new size, or the operation will fail.
Indexes
Databases use indexes to quickly locate data without having to search through every row for matches. To ensure the best performance, Appwrite recommends an index for every column queried. If you plan to query multiple columns in a single query, creating an index with all queried columns will yield optimal performance.
The following indexes are currently supported:
Type | Description |
key | Plain Index to allow queries. |
unique | Unique Index to disallow duplicates. |
fulltext | For searching within string columns. Required for the search query method. |
You can create an index by navigating to your table's Indexes tab or by using your favorite Server SDK.