Documentation ¶
Index ¶
- func CreateAlbumWithRandomTracks(db *gorm.DB, albumTitle string, singerId int64, numTracks int) (int64, error)
- func CreateInterleavedTablesIfNotExist(w io.Writer, db *gorm.DB) error
- func CreateRandomSingersAndAlbums(w io.Writer, db *gorm.DB) error
- func CreateSinger(db *gorm.DB, firstName, lastName string) (int64, error)
- func CreateVenueAndConcertInTransaction(w io.Writer, db *gorm.DB) error
- func DeleteAllData(db *gorm.DB) error
- func DeleteRandomAlbum(w io.Writer, db *gorm.DB) error
- func DeleteRandomTrack(w io.Writer, db *gorm.DB) error
- func FirstOrCreateVenue(w io.Writer, db *gorm.DB, name string) error
- func FirstOrInitVenue(w io.Writer, db *gorm.DB, name string) error
- func PrintAlbumsFirstCharTitleAndFirstOrLastNameEqual(w io.Writer, db *gorm.DB) error
- func PrintAlbumsReleaseBefore1900(w io.Writer, db *gorm.DB) error
- func PrintConcerts(w io.Writer, db *gorm.DB) error
- func PrintSingersAlbumsAndTracks(w io.Writer, db *gorm.DB) error
- func PrintSingersWithLimitAndOffset(w io.Writer, db *gorm.DB) error
- func QueryWithJsonParameter(w io.Writer, db *gorm.DB) error
- func QueryWithTimeout(w io.Writer, db *gorm.DB) error
- func RunSample(w io.Writer, connString string) error
- func SearchAlbumsUsingNamedArgument(w io.Writer, db *gorm.DB, title string) error
- func UpdateDataWithJsonColumn(w io.Writer, db *gorm.DB) error
- func UpdateTracksInBatches(w io.Writer, db *gorm.DB) error
- func UpdateVenueDescription(w io.Writer, db *gorm.DB) error
- type Album
- type Concert
- type Singer
- type Track
- type Venue
- type VenueDetails
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateAlbumWithRandomTracks ¶
func CreateAlbumWithRandomTracks(db *gorm.DB, albumTitle string, singerId int64, numTracks int) (int64, error)
CreateAlbumWithRandomTracks creates and stores a new Album in the database. Also generates numTracks random tracks for the Album. Returns the ID of the Album.
func CreateInterleavedTablesIfNotExist ¶
CreateInterleavedTablesIfNotExist creates all tables that are required for this sample if they do not yet exist.
func CreateRandomSingersAndAlbums ¶
CreateRandomSingersAndAlbums creates some random test records and stores these in the database.
func CreateSinger ¶
CreateSinger creates a new Singer and stores in the database. Returns the ID of the Singer.
func CreateVenueAndConcertInTransaction ¶
CreateVenueAndConcertInTransaction creates a new Venue and a Concert in a read/write transaction.
func DeleteAllData ¶
DeleteAllData deletes all existing records in the database.
func DeleteRandomAlbum ¶
DeleteRandomAlbum deletes a random Album. The Album could have one or more Tracks interleaved with it, but as the `INTERLEAVE IN PARENT` clause includes `ON DELETE CASCADE`, the child rows will be deleted along with the parent.
func DeleteRandomTrack ¶
DeleteRandomTrack will delete a randomly chosen Track from the database. This function shows how to delete a record with a primary key consisting of more than one column.
func FirstOrCreateVenue ¶
FirstOrCreateVenue tries to fetch an existing Venue from the database based on the name of the venue, and if not found, creates a new Venue record in the database.
func FirstOrInitVenue ¶
FirstOrInitVenue tries to fetch an existing Venue from the database based on the name of the venue, and if not found, initializes a Venue struct. This can then be used to create or update the record.
func PrintConcerts ¶
PrintConcerts prints the current concerts in the database to the console. It will preload all its associations, so it can directly print the properties of these as well.
func PrintSingersAlbumsAndTracks ¶
PrintSingersAlbumsAndTracks queries and prints all Singers, Albums and Tracks in the database.
func QueryWithTimeout ¶
QueryWithTimeout will try to execute a query with a 1ms timeout. This will normally cause a Deadline Exceeded error to be returned.
func SearchAlbumsUsingNamedArgument ¶
SearchAlbumsUsingNamedArgument searches for Albums using a named argument.
func UpdateTracksInBatches ¶
UpdateTracksInBatches uses FindInBatches to iterate through a selection of Tracks in batches and updates each Track that it found.
Types ¶
type Track ¶
type Track struct { gorm.Model TrackNumber int64 `gorm:"primaryKey;autoIncrement:false"` Title string SampleRate float64 Album Album `gorm:"foreignKey:id"` }
Track is interleaved in Album. The ID column is both the first part of the primary key of Track, and a reference to the Album that owns the Track.
type VenueDetails ¶
type VenueDetails struct { Name spanner.NullString `json:"name"` Rating spanner.NullFloat64 `json:"rating"` Open interface{} `json:"open"` Tags []spanner.NullString `json:"tags"` }