0

Create Database

by
Published Sep 27, 2024

Creates a new database in a group for the organization or user.

Script turso Verified

The script

Submitted by hugo697 Bun
Verified 621 days ago
1
//native
2
type Turso = {
3
	apiToken: string
4
}
5

6
export async function main(
7
	resource: Turso,
8
	organizationSlug: string,
9
	databaseProperties: {
10
		name: string
11
		group: string
12
		size_limit?: string
13
		is_schema?: boolean
14
		schema?: string
15
	}
16
) {
17
	const endpoint = `https://api.turso.tech/v1/organizations/${organizationSlug}/databases`
18

19
	const response = await fetch(endpoint, {
20
		method: 'POST',
21
		headers: {
22
			Authorization: `Bearer ${resource.apiToken}`,
23
			'Content-Type': 'application/json'
24
		},
25
		body: JSON.stringify(databaseProperties)
26
	})
27

28
	if (!response.ok) {
29
		throw new Error(`HTTP error! status: ${response.status}`)
30
	}
31

32
	const data = await response.json()
33

34
	return data
35
}
36