Skip to content

louvri/gosl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gosl


gosl is a library that provides common golang's sql builder.
This README is still not fully completed yet, will be updated shortly. The codes were created by @johnjerrico, published here so it can be used publicly.

Installation


Get the code with:

$ go get github.com/louvri/gosl

Usage


On your request model add the transformer if you want:

type Request struct {
	...
	Transformer *transformer.Transformer
}

Then put it at your request object creation/modification:

...
    Object: search.Request{
        ...,
        Transformer: &transformer.Transformer{
            Store: func(data interface{}) error {
                return request.Transformer.Store(data)
            },
            Transform: func(data interface{}) (interface{}, error) {
                tmp := data.(dbModel.Model)
                tmp.Status = constant.StatusMap[tmp.Status]
                transformedSales, _ := request.Transformer.Transform(tmp)
                return transformedSales, nil
            },
        },
    }
...

And call it within the sql retrieval codes:

    ...
    for rows.Next() {
        ...
        _, err = obj.Transform(result)
        if err != nil {
            return err
        }
        ...
    }
    ...