-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): Adding readme file for the inserter package (#83)
Adding readme file for the inserter package
- Loading branch information
1 parent
67aa17d
commit 6ab75e0
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Inserter Package | ||
|
||
The `inserter` package provides functionality to insert data into a database using Go. It is designed to be flexible and easy to use. | ||
|
||
## Installation | ||
|
||
To install the `inserter` package, use the following command: | ||
|
||
```sh | ||
go get github.com/jacobbrewer1/patcher/inserter | ||
``` | ||
|
||
## Usage | ||
|
||
Here is an example of how to use the inserter package: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/jacobbrewer1/patcher/inserter" | ||
) | ||
|
||
type User struct { | ||
ID int `db:"id,pk,autoinc"` // pk = primary key (This field will be ignored by default by the inserter package), autoinc = auto increment | ||
Name string `db:"name"` | ||
Email string `db:"email"` | ||
} | ||
|
||
func main() { | ||
user := User{ | ||
Name: "John Doe", | ||
Email: "[email protected]", | ||
} | ||
|
||
sql, args, err := inserter.NewBatch([]any{user}, inserter.WithTable("users")).GenerateSQL() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println(sql) | ||
fmt.Println(args) | ||
} | ||
|
||
``` | ||
|
||
This will output the following: | ||
|
||
```SQL | ||
INSERT INTO users (id, name, email) VALUES (?, ?, ?) | ||
``` | ||
|
||
with the following arguments: | ||
|
||
``` | ||
[1, "John Doe", "[email protected]"] | ||
``` | ||
|
||
## Configuration Options | ||
|
||
### GenerateInsertSQL Options | ||
|
||
* `WithTable(tableName string)`: Specify the table name for the SQL query. | ||
|
||
## Contributing | ||
|
||
We welcome contributions! Please follow these steps to contribute: | ||
|
||
1. Fork the repository. | ||
2. Create a new branch for your feature or bugfix. | ||
3. Write tests for your changes. | ||
4. Run the tests to ensure everything works. | ||
5. Submit a pull request. | ||
|
||
To run tests, use the following command: | ||
|
||
```sh | ||
go test ./... | ||
``` | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the [LICENSE](../LICENSE) file for details. |