pg

package
v0.0.0-...-7e0198b Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2021 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Array

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

Example
package main

import (
	"fmt"

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

func main() {
	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

func JSON(value interface{}) sqrl.Sqlizer

JSON converts value into Postgres JSON

func JSONB

func JSONB(value interface{}) sqrl.Sqlizer

JSONB converts value into Postgres JSONB

Example
package main

import (
	"fmt"

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

func main() {
	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"]]

Types

This section is empty.

Jump to

Keyboard shortcuts

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