The Database Go Package is a collection of tools for working with databases in Go applications. It provides functionalities for managing database connections, executing commands, and handling rows and tables. With this package, developers can easily interact with databases in their Go projects, making database-related tasks more efficient and straightforward.
go get github.com/fatihtatoglu/db-go
config := db.CreateNewDBConfig("mysql", "username", "password", "localhost", 3306, "database_name")
connection, err := db.CreateNewDBConnection(config)
if err != nil {
// handle error
}
err = connection.Open()
if err != nil {
// handle error
}
defer connection.Close()
command, err := db.CreateNewDBCommand(connection)
if err != nil {
// handle error
}
_, err = command.Execute("CREATE TABLE users (name VARCHAR(255), age INT)")
if err != nil {
// handle error
}
result, err := db.Execute("INSERT INTO users (name, age) VALUES (?, ?)", "John Doe", 30)
if err != nil {
// handle error
}
fmt.Println("Rows affected:", result.RowsAffected)
query := "SELECT * FROM users"
result, err := command.Query(query)
if err != nil {
// handle error
}
query := "SELECT * FROM users WHERE age > ?"
result, err := command.Query(query, 25)
if err != nil {
// handle error
}
- Support for various database drivers including;
- MySQL
- PostgreSQL
- SQLite
- SQL Server
- Easy-to-use API for executing SQL queries, fetching data, and managing database connections
- Efficient handling of database transactions and error handling
This project is licensed under the MIT License - see the LICENSE file for details.