package
0.1.16
Repository: https://github.com/jacobbrewer1/patcher.git
Documentation: pkg.go.dev

# README

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:

go get github.com/jacobbrewer1/patcher/inserter

Usage

Here is an example of how to use the inserter package:

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:

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:

go test ./...

License

This project is licensed under the MIT License. See the LICENSE file for details.

# Functions

No description provided by the author
NewMockBatchOpt creates a new instance of MockBatchOpt.
WithDB sets the database connection to use.
WithIgnoreFields sets the fields to ignore when patching.
WithIgnoreFieldsFunc sets the function that determines whether a field should be ignored.
WithIncludePrimaryKey determines whether the primary key should be included in the insert.
WithTable sets the table name to use in the SQL statement.
WithTagName sets the tag name to look for in the struct.

# Variables

ErrNoArgs is returned when no arguments are set.
ErrNoDatabaseConnection is returned when no database connection is set.
ErrNoFields is returned when no fields are set.
ErrNoTable is returned when no table is set.

# Structs

MockBatchOpt is an autogenerated mock type for the BatchOpt type.
No description provided by the author

# Type aliases

No description provided by the author