database

package
v0.0.0-...-20ee73f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteBook

func DeleteBook(id int) error

func GetBookByISBN

func GetBookByISBN(isbn string) (error, *model.Book)

GetBookByISBN retrieves a book from the database based on its ISBN.

Parameters:

  • isbn: A string that represents the ISBN of the book to be retrieved.

Returns:

  • error: An error if the retrieval fails.
  • *model.Book: A pointer to the model.Book struct that represents the book retrieved from the database.

func GetBookById

func GetBookById(id int) (error, *model.Book)

func InitDatabase

func InitDatabase() error

InitDatabase initializes the database connection and performs automatic migration for the defined models.

It takes no parameters and returns an error if the initialization or migration fails.

Example:

err := database.InitDatabase()
if err != nil {
	log.Fatal(err)
}
fmt.Println("Database initialized successfully.")

func StoreBook

func StoreBook(book *model.Book) error

func UpdateBook

func UpdateBook(book *model.Book) error

UpdateBook updates an existing book in the database.

Parameters:

  • book: A pointer to the model.Book struct that represents the book to be updated.

Returns:

  • error: An error if the update fails.

Example:

book := &model.Book{ID: 1, Title: "New Title"}
err := database.UpdateBook(book)
if err != nil {
	log.Fatal(err)
}
fmt.Println("Book updated successfully.")

Types

type PostgresNamingStrategy

type PostgresNamingStrategy struct{}

func (PostgresNamingStrategy) CheckerName

func (p PostgresNamingStrategy) CheckerName(table, column string) string

func (PostgresNamingStrategy) ColumnName

func (p PostgresNamingStrategy) ColumnName(table, column string) string

func (PostgresNamingStrategy) IndexName

func (p PostgresNamingStrategy) IndexName(table, column string) string

func (PostgresNamingStrategy) JoinTableName

func (p PostgresNamingStrategy) JoinTableName(joinTable string) string

func (PostgresNamingStrategy) RelationshipFKName

func (p PostgresNamingStrategy) RelationshipFKName(relationship schema.Relationship) string

func (PostgresNamingStrategy) SchemaName

func (p PostgresNamingStrategy) SchemaName(table string) string

func (PostgresNamingStrategy) TableName

func (p PostgresNamingStrategy) TableName(table string) string

func (PostgresNamingStrategy) UniqueName

func (p PostgresNamingStrategy) UniqueName(table, column string) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL