lib

package
v0.0.0-...-d400e7b Latest Latest
Warning

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

Go to latest
Published: May 5, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddLimitToSqlSelectStatement

func AddLimitToSqlSelectStatement(s string, limit uint) string

AddLimitToSqlSelectStatement adds a limit to a SELECT statement. If the input starts with CREATE it does not add it.

func GenerateTestNameAcceptedValues

func GenerateTestNameAcceptedValues(test *servicev1.TestAcceptedValues) string

func GenerateTestNameCustomColumn

func GenerateTestNameCustomColumn(test *servicev1.TestCustomColumn) string

func GenerateTestNameNotNull

func GenerateTestNameNotNull(test *servicev1.TestNotNull) string

func GenerateTestNameRelationship

func GenerateTestNameRelationship(test *servicev1.TestRelationship) string

func GenerateTestNameUnique

func GenerateTestNameUnique(test *servicev1.TestUnique) string

func GenerateTestSqlAcceptedValues

func GenerateTestSqlAcceptedValues(test *servicev1.TestAcceptedValues) string

func GenerateTestSqlNotNull

func GenerateTestSqlNotNull(test *servicev1.TestNotNull) string

GenerateTestSqlNotNull generates a SQL test that checks that the given column does not contain any nulls.

The test was generated with the following template but has been optimized template.Must(template.New("sqlNotNull").Parse(`SELECT * FROM {{.Table}} WHERE {{.Column}} IS NULL`))

func GenerateTestSqlRelationship

func GenerateTestSqlRelationship(test *servicev1.TestRelationship) string

func GenerateTestSqlUnique

func GenerateTestSqlUnique(test *servicev1.TestUnique) string

func Init

func Init() embed.FS

Init returns the content of the init directory.

func NewFileSystem

func NewFileSystem(fs *servicev1.FileSystem) (*memfs.FS, error)

NewFileSystem generates an in memory filesystem from proto

func ParseConfig

func ParseConfig(r io.Reader) (*servicev1.Configuration, error)

ParseConfig parses bytes to configuration. It also applies any defaults to the configuration, as well as validates the configuration.

func ParseConfigFromPath

func ParseConfigFromPath(path string) (*servicev1.Configuration, error)

ParseConfigFromPath runs ParseConfig given path.

func ParseModelSchemasToViews

func ParseModelSchemasToViews(
	fileReader io.Reader,
	viewName string,
	configSchemaName string,
	nameReplacingStrategy func(name string) string,
) (string, error)

ParseModelSchemasToViews takes in a reader and reads it to a View file nameReplacingStrategy takes in the reference name and replaces it with whatever strategy is necessary.

func ParseProject

func ParseProject(c *servicev1.Configuration, fs fs.FS, projectRoot string) (*servicev1.Project, error)

ParseProject parses a whole project into a project object

func ParseProjectFile

func ParseProjectFile(reader io.Reader) (*servicev1.ProjectFile, error)

func ParseTableSchemaSeeds

func ParseTableSchemaSeeds(database databases.Database, tableName string, reader io.Reader, doNotIncludeData bool) ([]string, error)

ParseTableSchemaSeeds returns the SQL statements to create a table and insert the data from a CSV file. doNotIncludeData is used to generate only the create table statement without any inserts.

func ProjectAndFsToQuerySql

func ProjectAndFsToQuerySql(p *servicev1.Project, fsfs fs.FS, model string) (string, error)

ProjectAndFsToQuerySql returns a SELECT statement for the model specified such that it can be used.

func ProjectAndFsToSqlForViews

func ProjectAndFsToSqlForViews(p *servicev1.Project, fsfs fs.FS, database databases.Database, onlyModels bool, doNotIncludeSeedsData bool) ([][2]string, error)

ProjectAndFsToSqlForViews returns both the sql for the seeds and the sql for the models. The returned tuple is a slice of [2]string where the first element is the name of the seed or model and the second element is the sql. The seeds are returned first.

The returned Sql is in the shape of a view for models and tables for seeds.

The onlyModels flag is used to only return the sql for the models.

func ReplaceReferenceStringFound

func ReplaceReferenceStringFound(schemaName string, sources map[string]*servicev1.Source) func(string) string

ReplaceReferenceStringFound takes in a reference such as `tbd.raw_orders` where the schemaName is specified as `tbd` and replaces it with the value of the reference raw_orders. This is used to replace references in the sql files with the actual sql

For a reference to be replaced it must be in the form of `schemaName.referenceName`

For references in general, the schemaName is just removed. In the case that the reference is a source. The string is replaced by the path property of the source.

func ReturnSQLForModel

func ReturnSQLForModel(p *servicev1.Project, database databases.Database, fsfs fs.FS, modelName string) (string, error)

ReturnSQLForModel returns the sql for a model but does so in the shape to create a view

func ReturnTestsSQL

func ReturnTestsSQL(p *servicev1.Project, fsfs fs.FS) (map[string]string, error)

ReturnTestsSQL returns sql tests to run in no order but with the name pointing to the test TODO Need to write a test for this TODO Need to add safe adders for the tests map

func RunTestSql

func RunTestSql(ctx context.Context, db databases.Database, sql string) error

RunTestSql runs a test sql statement and returns an error if the test fails

func ValidateModelName

func ValidateModelName(name string) error

ValidateModelName validates a model name.

Types

type GonumGraph

type GonumGraph struct {
	*simple.DirectedGraph
	// contains filtered or unexported fields
}

func NewGraph

func NewGraph(edges [][2]string) (*GonumGraph, error)

func (*GonumGraph) GetNode

func (g *GonumGraph) GetNode(name string) (int64, error)

GetNode returns node int64 for a given node name.

func (*GonumGraph) GetNodeName

func (g *GonumGraph) GetNodeName(id int64) (string, error)

func (*GonumGraph) GetNodeSorted

func (g *GonumGraph) GetNodeSorted() ([]string, error)

GetNodeSorted returns the nodes in the graph in a sorted order so that they can be applied in the right order. The order is determined by the order of the nodes in the graph.

TODO Make this deterministic by sorting the nodes by name.

func (*GonumGraph) ReturnSubGraphNodes

func (g *GonumGraph) ReturnSubGraphNodes(model string) ([]int64, error)

ReturnSubGraphNodes returns the subgraph that is needed to compile a particular model, in the order that if applied should be ok.

It will remove duplicate values if they are in output more than once.

func (*GonumGraph) ToDotViz

func (g *GonumGraph) ToDotViz() ([]byte, error)

type GonumGraphNode

type GonumGraphNode struct {
	simple.Node
	// contains filtered or unexported fields
}

func (GonumGraphNode) DOTID

func (g GonumGraphNode) DOTID() string

type ModelDefinitions

type ModelDefinitions map[string]*servicev1.ProjectFile_Model

type PathMap

type PathMap map[string]string

PathMap is a map of names to paths that includes models and sources to be used to convert model names to paths in test creation

type ProjectGraph

type ProjectGraph struct {
	// contains filtered or unexported fields
}

func ProjectToGraph

func ProjectToGraph(p *servicev1.Project) (ProjectGraph, error)

func (ProjectGraph) ToDotViz

func (g ProjectGraph) ToDotViz() ([]byte, error)

type StandardTestTypes

type StandardTestTypes string
const (
	StandardTestTypeSqlNotNull     StandardTestTypes = "not_null"
	StandardTestTypeSqlUnique      StandardTestTypes = "unique"
	StandardTestTypeRelationship   StandardTestTypes = "relationship"
	StandardTestTypeAcceptedValues StandardTestTypes = "accepted_values"
)

Directories

Path Synopsis
databaseImplementationBase
Package databaseImplementationBase provides a base class for the database implementations.
Package databaseImplementationBase provides a base class for the database implementations.

Jump to

Keyboard shortcuts

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