https://github.com/fatihtatoglu/db-go
Generic database package for Go (golang)
https://github.com/fatihtatoglu/db-go
database golang golang-package
Last synced: 2 months ago
JSON representation
Generic database package for Go (golang)
- Host: GitHub
- URL: https://github.com/fatihtatoglu/db-go
- Owner: fatihtatoglu
- License: mit
- Created: 2024-03-13T08:55:08.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-01T22:10:38.000Z (over 2 years ago)
- Last Synced: 2024-06-21T14:14:11.869Z (about 2 years ago)
- Topics: database, golang, golang-package
- Language: Go
- Homepage:
- Size: 28.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# db-go
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.
## Install
```bash
go get github.com/fatihtatoglu/db-go
```
## Usage
### Creating a Database Connection
```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()
```
### Executing Commands
```go
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
}
```
### Executing Commands with Parameters
```go
result, err := db.Execute("INSERT INTO users (name, age) VALUES (?, ?)", "John Doe", 30)
if err != nil {
// handle error
}
fmt.Println("Rows affected:", result.RowsAffected)
```
### Querying Data
```go
query := "SELECT * FROM users"
result, err := command.Query(query)
if err != nil {
// handle error
}
```
### Querying Data with Parameters
```go
query := "SELECT * FROM users WHERE age > ?"
result, err := command.Query(query, 25)
if err != nil {
// handle error
}
```
## Features
- [X] Support for various database drivers including;
- [X] 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
## Credits
- [Fatih Tatoğlu](https://github.com/fatihtatoglu)
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.