blob: 0479d0e6eb7032384e4dd373f38c6a7763f486bd [file] [log] [blame]
Jamie Hannaford1943b382015-02-12 11:50:02 +01001package databases
2
3import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
Jamie Hannaford1943b382015-02-12 11:50:02 +01006)
7
Jamie Hannaford9793d942015-02-18 15:13:20 +01008// Database represents a Database API resource.
Jamie Hannaford1943b382015-02-12 11:50:02 +01009type Database struct {
Jamie Hannaford9793d942015-02-18 15:13:20 +010010 // Specifies the name of the MySQL database.
Jamie Hannaford1943b382015-02-12 11:50:02 +010011 Name string
12
13 // Set of symbols and encodings. The default character set is utf8.
14 CharSet string
15
16 // Set of rules for comparing characters in a character set. The default
17 // value for collate is utf8_general_ci.
18 Collate string
19}
20
Jamie Hannaford9793d942015-02-18 15:13:20 +010021// CreateResult represents the result of a Create operation.
Jamie Hannaford1943b382015-02-12 11:50:02 +010022type CreateResult struct {
Jamie Hannaford11108402015-02-23 10:31:41 +010023 gophercloud.ErrResult
Jamie Hannaford1943b382015-02-12 11:50:02 +010024}
25
Jamie Hannaford9793d942015-02-18 15:13:20 +010026// DeleteResult represents the result of a Delete operation.
27type DeleteResult struct {
28 gophercloud.ErrResult
29}
30
Jamie Hannaford1943b382015-02-12 11:50:02 +010031// DBPage represents a single page of a paginated DB collection.
32type DBPage struct {
33 pagination.LinkedPageBase
34}
35
36// IsEmpty checks to see whether the collection is empty.
37func (page DBPage) IsEmpty() (bool, error) {
38 dbs, err := ExtractDBs(page)
Jon Perritt12395212016-02-24 10:41:17 -060039 return len(dbs) == 0, err
Jamie Hannaford1943b382015-02-12 11:50:02 +010040}
41
42// NextPageURL will retrieve the next page URL.
43func (page DBPage) NextPageURL() (string, error) {
Jon Perritt12395212016-02-24 10:41:17 -060044 var s struct {
45 Links []gophercloud.Link `json:"databases_links"`
Jamie Hannaford1943b382015-02-12 11:50:02 +010046 }
Jon Perritt12395212016-02-24 10:41:17 -060047 err := page.ExtractInto(&s)
Jamie Hannaford1943b382015-02-12 11:50:02 +010048 if err != nil {
49 return "", err
50 }
Jon Perritt12395212016-02-24 10:41:17 -060051 return gophercloud.ExtractNextURL(s.Links)
Jamie Hannaford1943b382015-02-12 11:50:02 +010052}
53
54// ExtractDBs will convert a generic pagination struct into a more
55// relevant slice of DB structs.
56func ExtractDBs(page pagination.Page) ([]Database, error) {
Jon Perritt12395212016-02-24 10:41:17 -060057 r := page.(DBPage)
58 var s struct {
59 Databases []Database `json:"databases"`
Jamie Hannaford1943b382015-02-12 11:50:02 +010060 }
Jon Perritt12395212016-02-24 10:41:17 -060061 err := r.ExtractInto(&s)
62 return s.Databases, err
Jamie Hannaford1943b382015-02-12 11:50:02 +010063}