Skip to content

Commit

Permalink
Use new API for seeding databases during creation
Browse files Browse the repository at this point in the history
  • Loading branch information
athoscouto committed Sep 13, 2023
1 parent 25c3ada commit 420d3cf
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions internal/turso/databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,27 @@ type CreateDatabaseResponse struct {
Username string
}

func (d *DatabasesClient) Create(name, region, image, extensions, group, fork string) (*CreateDatabaseResponse, error) {
type Body struct{ Name, Region, Image, Extensions, Group, Fork string }
body, err := marshal(Body{name, region, image, extensions, group, fork})
type DBSeed struct {
Value string `json:"value"`
Type string `json:"type"`
}

type CreateDatabaseBody struct {
Name string `json:"name"`
Location string `json:"location"`
Image string `json:"image,omitempty"`
Extensions string `json:"extensions,omitempty"`
Group string `json:"group,omitempty"`
Seed *DBSeed `json:"seed,omitempty"`
}

func (d *DatabasesClient) Create(name, location, image, extensions, group, fromDB string) (*CreateDatabaseResponse, error) {
params := CreateDatabaseBody{name, location, image, extensions, group, nil}
if fromDB != "" {
params.Seed = &DBSeed{fromDB, "database"}
}

body, err := marshal(params)
if err != nil {
return nil, fmt.Errorf("could not serialize request body: %w", err)
}
Expand Down

0 comments on commit 420d3cf

Please sign in to comment.