diff --git a/README.md b/README.md index 4003f56..a12d3f2 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,38 @@ of the need to generate patches for a database; when a new field is added to a s new `if` checks to be created in the codebase. This library aims to solve that problem by generating the SQL patches for you. +## What is Patcher? + +* **Automatic SQL Generation**: It automatically generates SQL UPDATE queries from structs, reducing the need for + manually + writing and maintaining SQL statements. +* **Code Simplification**: It reduces the amount of boilerplate code and if-else conditions required to handle different + struct fields, making the codebase cleaner and easier to maintain. +* **Struct Diffs**: It allows injecting changes from one struct to another and generating update scripts based on + differences, streamlining the process of synchronizing data changes. +* **Join Support**: It supports generating SQL joins by creating structs that implement the Joiner interface, + simplifying + the process of managing related data across multiple tables. + ## Usage +### Configuration + +#### LoadDiff Options + +* `includeZeroValues`: Set to true to include zero values in the diff. +* `includeNilValues`: Set to true to include nil values in the diff. + +#### GenerateSQL Options + +* `WithTable(tableName string)`: Specify the table name for the SQL query. +* `WithWhere(whereClause WhereTyper)`: Provide a where clause for the SQL query. +* `WithJoin(joinClause Joiner)`: Add join clauses to the SQL query. +* `includeZeroValues`: Set to true to include zero values in the diff. (Only for NewDiffSQLPatch) +* `includeNilValues`: Set to true to include nil values in the diff. (Only for NewDiffSQLPatch) + +### Basic Examples + #### Basic To use the library, you need to create a struct that represents the table you want to generate patches for. The struct @@ -254,6 +284,34 @@ the [Joiner](./joiner.go) interface. Once you have the join struct, you can pass it to the `GenerateSQL` function using the `WithJoin` option. You can add as many of these as you would like. -# Examples +## Installation + +To install the Patcher library, use the following command: + +```sh +go get github.com/jacobbrewer1/patcher +``` + +## Examples You can find examples of how to use this library in the [examples](./examples) directory. + +## 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.