dbmap

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: MIT Imports: 1 Imported by: 0

README

DbMap

Tiny zero-dependency package to auto map struct fields to database columns and vice versa without ORM's.

Go Report Card

Usage

import (
    "github.com/AlexanderMatveev/dbmap"
    "github.com/Masterminds/squirrel"
)

type Entity struct {
    Id            int       `db:"id"`
    Name          string    `db:"name"`
    DateTimeField time.Time `db:"created_at"`
    FieldNotIdDb  int
    NullableField *int
}

var structColumns = dbmap.Columns(reflect.TypeOf(Entity{}))

func main(){
    var e Entity
    // ...
    squirrel.Select(structColumns...)
    // ...
    rows.Scan(dbmap.Scan(&e)...)
    // ...
    squirrel.Insert("table").Columns(structColumns...).Values(dbmap.Values(e)...)
    // ...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Columns

func Columns(t reflect.Type) []string

func Scan

func Scan(s any) []any

func Values

func Values(s any) []any

Types

This section is empty.

Jump to

Keyboard shortcuts

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