Jamie Hannaford | 1943b38 | 2015-02-12 11:50:02 +0100 | [diff] [blame] | 1 | package databases |
| 2 | |
| 3 | import ( |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 4 | "github.com/gophercloud/gophercloud" |
| 5 | "github.com/gophercloud/gophercloud/pagination" |
Jamie Hannaford | 1943b38 | 2015-02-12 11:50:02 +0100 | [diff] [blame] | 6 | ) |
| 7 | |
Jamie Hannaford | 9793d94 | 2015-02-18 15:13:20 +0100 | [diff] [blame] | 8 | // Database represents a Database API resource. |
Jamie Hannaford | 1943b38 | 2015-02-12 11:50:02 +0100 | [diff] [blame] | 9 | type Database struct { |
Jamie Hannaford | 9793d94 | 2015-02-18 15:13:20 +0100 | [diff] [blame] | 10 | // Specifies the name of the MySQL database. |
Jamie Hannaford | 1943b38 | 2015-02-12 11:50:02 +0100 | [diff] [blame] | 11 | 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 Hannaford | 9793d94 | 2015-02-18 15:13:20 +0100 | [diff] [blame] | 21 | // CreateResult represents the result of a Create operation. |
Jamie Hannaford | 1943b38 | 2015-02-12 11:50:02 +0100 | [diff] [blame] | 22 | type CreateResult struct { |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 23 | gophercloud.ErrResult |
Jamie Hannaford | 1943b38 | 2015-02-12 11:50:02 +0100 | [diff] [blame] | 24 | } |
| 25 | |
Jamie Hannaford | 9793d94 | 2015-02-18 15:13:20 +0100 | [diff] [blame] | 26 | // DeleteResult represents the result of a Delete operation. |
| 27 | type DeleteResult struct { |
| 28 | gophercloud.ErrResult |
| 29 | } |
| 30 | |
Jamie Hannaford | 1943b38 | 2015-02-12 11:50:02 +0100 | [diff] [blame] | 31 | // DBPage represents a single page of a paginated DB collection. |
| 32 | type DBPage struct { |
| 33 | pagination.LinkedPageBase |
| 34 | } |
| 35 | |
| 36 | // IsEmpty checks to see whether the collection is empty. |
| 37 | func (page DBPage) IsEmpty() (bool, error) { |
| 38 | dbs, err := ExtractDBs(page) |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 39 | return len(dbs) == 0, err |
Jamie Hannaford | 1943b38 | 2015-02-12 11:50:02 +0100 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | // NextPageURL will retrieve the next page URL. |
| 43 | func (page DBPage) NextPageURL() (string, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 44 | var s struct { |
| 45 | Links []gophercloud.Link `json:"databases_links"` |
Jamie Hannaford | 1943b38 | 2015-02-12 11:50:02 +0100 | [diff] [blame] | 46 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 47 | err := page.ExtractInto(&s) |
Jamie Hannaford | 1943b38 | 2015-02-12 11:50:02 +0100 | [diff] [blame] | 48 | if err != nil { |
| 49 | return "", err |
| 50 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 51 | return gophercloud.ExtractNextURL(s.Links) |
Jamie Hannaford | 1943b38 | 2015-02-12 11:50:02 +0100 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | // ExtractDBs will convert a generic pagination struct into a more |
| 55 | // relevant slice of DB structs. |
| 56 | func ExtractDBs(page pagination.Page) ([]Database, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 57 | r := page.(DBPage) |
| 58 | var s struct { |
| 59 | Databases []Database `json:"databases"` |
Jamie Hannaford | 1943b38 | 2015-02-12 11:50:02 +0100 | [diff] [blame] | 60 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 61 | err := r.ExtractInto(&s) |
| 62 | return s.Databases, err |
Jamie Hannaford | 1943b38 | 2015-02-12 11:50:02 +0100 | [diff] [blame] | 63 | } |