gotidus: Index | Files | Directories

package gotidus

import ""

Package gotidus is an SQL anonymization view builder for go


fooTable := gotidus.NewTable()
// Define columns on the table to anonymize in a specific way.
// Other columns will just contain their normal value.
// Note: Any column defined but not actually in the table will be ignored.
    gotidus.NewStaticAnonymizer("staticValue", "TEXT"),
generator := gotidus.NewGenerator(postgres.NewQueryBuilder())
// Define tables that should have specifically anonymized columns.
// Tables that are not supposed to be anonymized specifically,
// do not have to be defined.
// Note: Any table defined but not actually in the database will be ignored.
generator.AddTable("foo", fooTable)

// Clear existing views
err := generator.ClearViews(db)
if err != nil {

// ... database migration

// Create new views
err = generator.CreateViews(db)
if err != nil {


Package Files

anonymizer.go doc.go generator.go table.go


const DefaultViewPostfix = "anonymized"

DefaultViewPostfix defines the postfix given to views to distinguish them from the table names.

func FullColumnName Uses

func FullColumnName(tableName, columnName string) string

FullColumnName is a helper function that allows building the name based on the table and column names.

type Anonymizer Uses

type Anonymizer interface {
    Build(tableName, columnName string) string

Anonymizer is the interface for functions that build the query snippet to anonymize a specific column.

type Generator Uses

type Generator struct {
    // contains filtered or unexported fields

Generator is the type orchestrating the view clearing and creation, based on the table config.

func NewGenerator Uses

func NewGenerator(queryBuilder QueryBuilder, options ...GeneratorOption) *Generator

NewGenerator initializes a new Generator object. It requires a QueryBuilder object and can be enhanced with GeneratorOption functions.

func (*Generator) AddTable Uses

func (g *Generator) AddTable(name string, table *Table) *Generator

AddTable adds a Table configuration to the generator with the given name. If this function is called again with the same name, it will overwrite the existing table.

func (*Generator) ClearViews Uses

func (g *Generator) ClearViews(db *sql.DB) error

ClearViews removes any potentially existing views that exist with the configured postfix.

func (*Generator) CreateViews Uses

func (g *Generator) CreateViews(db *sql.DB) error

CreateViews creates views named <table_name>_<postfix> for each table that could be found. It uses the configuration set before CreateViews was called.

func (*Generator) GetTable Uses

func (g *Generator) GetTable(name string) *Table

GetTable retrieves a Table from the config. If a Table was configured for the given name, that Table object will be returned. If no Table was configured for the given name, a blank table configuration is returned.

func (*Generator) ViewName Uses

func (g *Generator) ViewName(tableName string) string

ViewName builds the view name from the table name and the postfix to <table_name>_<postfix>.

type GeneratorOption Uses

type GeneratorOption func(*Generator)

GeneratorOption is a function type following the option function pattern. It can be used to define methods of configuring the Generator object.

func WithViewPostfix Uses

func WithViewPostfix(viewPostfix string) GeneratorOption

WithViewPostfix is a GeneratorOption builder, which allows configuring the view postfix.

type NoopAnonymizer Uses

type NoopAnonymizer struct{}

NoopAnonymizer is an Anonymizer interface implementation which returns the column value is as. It is also the default anonymizer for every column unless otherwise defined.

func NewNoopAnonymizer Uses

func NewNoopAnonymizer() *NoopAnonymizer

NewNoopAnonymizer initializes a new NoopAnonymizer object

func (*NoopAnonymizer) Build Uses

func (a *NoopAnonymizer) Build(tableName, columnName string) string

Build returns the column name build from the table and column name

type QueryBuilder Uses

type QueryBuilder interface {
    ListViewsQuery() string
    DropViewQuery(viewName string) string

    ListTablesQuery() string

    ListColumnsQuery() string

    CreateViewQuery(viewName string, tableName string, columns []string) string

QueryBuilder is the interface used to implement support for different databases.

type StaticAnonymizer Uses

type StaticAnonymizer struct {
    // contains filtered or unexported fields

StaticAnonymizer is an Anonymizer interfface implementation that ensures that every row returns the same static value.

func NewStaticAnonymizer Uses

func NewStaticAnonymizer(staticValue, dataType string) *StaticAnonymizer

NewStaticAnonymizer initializes a new StaticAnonymizer object

func (*StaticAnonymizer) Build Uses

func (a *StaticAnonymizer) Build(tableName, columnName string) string

Build returns a partial query from the static value and data type given on object initialization. table and column name are ignored here.

type Table Uses

type Table struct {
    // contains filtered or unexported fields

Table is the type holding the column configuration

func NewTable Uses

func NewTable() *Table

NewTable initializes a Table object wich blank columns.

func (*Table) AddAnonymizer Uses

func (t *Table) AddAnonymizer(columnName string, anonymizer Anonymizer) *Table

AddAnonymizer allows setting a specific Anonymizer for a column of the given name. If an Anonymizer was previously configured for a column name, it will be overwritten.

func (*Table) GetAnonymizer Uses

func (t *Table) GetAnonymizer(columnName string) Anonymizer

GetAnonymizer retrieves an Anonymizer from the Table configuration. If an Anonymizer was configured for the given name, that Anonymizer will be returned. If no Anonymizer was configured for the given name, the NoopAnonymizer will be returned.


postgresPackage postgres is a PosgreSQL specific implementation of the 'gotidus.QueryBuilder' interface as well as several 'gotidus.Anonymizer' interface.

Package gotidus imports 2 packages (graph) and is imported by 1 packages. Updated 2020-07-29. Refresh now. Tools for package owners.