github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/db/v1/databases/results.go (about)

     1  package databases
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  // Database represents a Database API resource.
     9  type Database struct {
    10  	// Specifies the name of the MySQL database.
    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  
    21  // CreateResult represents the result of a Create operation.
    22  type CreateResult struct {
    23  	golangsdk.ErrResult
    24  }
    25  
    26  // DeleteResult represents the result of a Delete operation.
    27  type DeleteResult struct {
    28  	golangsdk.ErrResult
    29  }
    30  
    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)
    39  	return len(dbs) == 0, err
    40  }
    41  
    42  // NextPageURL will retrieve the next page URL.
    43  func (page DBPage) NextPageURL() (string, error) {
    44  	var s struct {
    45  		Links []golangsdk.Link `json:"databases_links"`
    46  	}
    47  	err := page.ExtractInto(&s)
    48  	if err != nil {
    49  		return "", err
    50  	}
    51  	return golangsdk.ExtractNextURL(s.Links)
    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) {
    57  	r := page.(DBPage)
    58  	var s struct {
    59  		Databases []Database `json:"databases"`
    60  	}
    61  	err := r.ExtractInto(&s)
    62  	return s.Databases, err
    63  }