mssqldb

package
v0.0.0-...-5552a58 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// PrimaryKeyViolation is the SQL code used by MsSql to indicate an attempt
	// to insert an entry which violates the primary key constraint.
	PrimaryKeyViolation = 2627
)

Variables

This section is empty.

Functions

func InitDb

func InitDb(dbConfig Config) (*sql.DB, error)

InitDb creates and tests a database connection using the configuration given in dbConfig. After it establishes a connection it also ensures that the table exists.

func SanitizeSQLArg

func SanitizeSQLArg(s string) string

SanitizeSQLArg returns the input string sanitized for safe use in an SQL query as argument.

Types

type Config

type Config struct {
	Name              string `envconfig:"database,default=orderservice" json:"Name"`
	Host              string `envconfig:"host,default=127.0.0.1" json:"Host"`
	Port              int    `envconfig:"port,default=1433" json:"Port"`
	User              string `envconfig:"username,default=test" json:"User"`
	Pass              string `envconfig:"password,default=test" json:"-"` // hidden from logging
	DbOrdersTableName string `envconfig:"tablename,default=orders" json:"OrdersTable"`
}

Config is a struct used for configuring the connection and the usage of the database. It contains the information needed to form a connection string and the name of the table used for storing the data.

func (Config) String

func (config Config) String() string

String returns a printable representation of the config as JSON. Use the struct field tag `json:"-"` to hide fields that should not be revealed such as credentials and secrets.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL