sqrl: github.com/elgris/sqrl/pg Index | Examples | Files

package pg

import "github.com/elgris/sqrl/pg"

Index

Examples

Package Files

array.go json.go

func Array Uses

func Array(arr interface{}) sqrl.Sqlizer

Array converts value into Postgres Array

Valid values are slices or arrays of arbitrary depth with elements of type string, int, uint and float elements of any bit size Example: []int, [][]uint16, [2][2]int, []string

Code:

sql, args, err := sqrl.Insert("posts").
    Columns("content", "tags").
    Values("Lorem Ipsum", pg.Array([]string{"foo", "bar"})).
    PlaceholderFormat(sqrl.Dollar).
    ToSql()

if err != nil {
    panic(err)
}

fmt.Println(sql)
fmt.Println(args)

Output:

INSERT INTO posts (content,tags) VALUES ($1,$2)
[Lorem Ipsum {"foo","bar"}]

func JSON Uses

func JSON(value interface{}) sqrl.Sqlizer

JSON converts value into Postgres JSON

func JSONB Uses

func JSONB(value interface{}) sqrl.Sqlizer

JSONB converts value into Postgres JSONB

Code:

sql, args, err := sqrl.Insert("posts").
    Columns("content", "tags").
    Values("Lorem Ipsum", pg.JSONB([]string{"foo", "bar"})).
    PlaceholderFormat(sqrl.Dollar).
    ToSql()

if err != nil {
    panic(err)
}

fmt.Println(sql)
fmt.Println(args)

Output:

INSERT INTO posts (content,tags) VALUES ($1,$2::jsonb)
[Lorem Ipsum ["foo","bar"]]

Package pg imports 7 packages (graph). Updated 2018-05-22. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).