Documentation
¶
Index ¶
- func DeleteBook(id int) error
- func GetBookByISBN(isbn string) (error, *model.Book)
- func GetBookById(id int) (error, *model.Book)
- func InitDatabase() error
- func StoreBook(book *model.Book) error
- func UpdateBook(book *model.Book) error
- type PostgresNamingStrategy
- func (p PostgresNamingStrategy) CheckerName(table, column string) string
- func (p PostgresNamingStrategy) ColumnName(table, column string) string
- func (p PostgresNamingStrategy) IndexName(table, column string) string
- func (p PostgresNamingStrategy) JoinTableName(joinTable string) string
- func (p PostgresNamingStrategy) RelationshipFKName(relationship schema.Relationship) string
- func (p PostgresNamingStrategy) SchemaName(table string) string
- func (p PostgresNamingStrategy) TableName(table string) string
- func (p PostgresNamingStrategy) UniqueName(table, column string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteBook ¶
func GetBookByISBN ¶
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 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 UpdateBook ¶
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
Click to show internal directories.
Click to hide internal directories.