fpgopg

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2021 License: MIT Imports: 4 Imported by: 0

README

go-filterparams-gopg

go-pg query generator for use with go-filterparams.

Currently in an experimental state. Do expect bugs!

Usage

To use, simply create an instance of Parser and call the AppendTo function with your original query.

package main

import (
    "github.com/cbrand/go-filterparams"
    "github.com/go-pg/pg/v10"
    "github.com/iancoleman/strcase"
    "github.com/pwnedgod/go-filterparams-gopg"
)

type User struct {
    tableName interface{} `pg:"users"`
    ID        string      `pg:",notnull,use_zero"`
    Username  string      `pg:",notnull,use_zero"`
    Password  string      `pg:",notnull,use_zero"`
}

func main() {
    var db *pg.DB

    //... obtain your go-pg query
    var users []*User
    pgQuery := db.Model(&users)

    //... obtain your query data
    var queryData *filterparams.QueryData

    // create a new parser
    parser := fpgopg.NewParser(fpgopg.NamingFunc(strcase.ToSnake))

    // append the parsed filterparams.QueryData
    pgQuery = parser.AppendTo(pgQuery, queryData)

    // perform select operation
    pgQuery.Select()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PassthroughNaming

func PassthroughNaming(name string) string

Types

type Naming

type Naming interface {
	Interpret(name string) string
}

type NamingFunc

type NamingFunc func(string) string

func (NamingFunc) Interpret

func (n NamingFunc) Interpret(name string) string

type Parser

type Parser interface {
	AppendTo(*pg.Query, *filterparams.QueryData) *pg.Query
}

func NewParser

func NewParser(naming Naming) Parser

Jump to

Keyboard shortcuts

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