spanddl

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package spannerddl provides primitives for in-memory modeling the DDL of Spanner databases.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Name    spansql.ID
	Type    spansql.Type
	NotNull bool
	Options spansql.ColumnOptions
}

Column represents a Spanner table column.

type Database

type Database struct {
	// Tables in the database.
	Tables []*Table
	// Indexes in the database.
	Indexes []*Index
}

Database represents an in-memory Spanner database.

Example
package main

import (
	"fmt"
	"io/ioutil"
	"path/filepath"

	"cloud.google.com/go/spanner/spansql"
	"go.einride.tech/aip-spanner/spanddl"
)

func main() {
	var db spanddl.Database
	files, err := filepath.Glob("../testdata/migrations/freight/*.up.sql")
	if err != nil {
		panic(err) // TODO: Handle error.
	}
	for _, file := range files {
		fileContent, err := ioutil.ReadFile(file)
		if err != nil {
			panic(err) // TODO: Handle error.
		}
		ddl, err := spansql.ParseDDL(file, string(fileContent))
		if err != nil {
			panic(err) // TODO: Handle error.
		}
		if err := db.ApplyDDL(ddl); err != nil {
			panic(err) // TODO: Handle error.
		}
	}
	for _, table := range db.Tables {
		fmt.Println(table.Name)
	}
}
Output:

shippers
sites
shipments
line_items

func (*Database) ApplyDDL

func (d *Database) ApplyDDL(ddl *spansql.DDL) error

ApplyDDL applies the provided DDL statement to the database.

func (*Database) Index

func (d *Database) Index(name spansql.ID) (*Index, bool)

Index looks up an index with the provided name.

func (*Database) Table

func (d *Database) Table(name spansql.ID) (*Table, bool)

Table looks up a table with the provided name.

type Index

type Index struct {
	Name         spansql.ID
	Table        spansql.ID
	Columns      []spansql.KeyPart
	Unique       bool
	NullFiltered bool
	Storing      []spansql.ID
	Interleave   spansql.ID
}

type Table

type Table struct {
	Name              spansql.ID
	Columns           []*Column
	InterleavedTables []*Table
	PrimaryKey        []spansql.KeyPart
	Interleave        *spansql.Interleave
}

Table represents a Spanner table.

func (*Table) Column

func (t *Table) Column(name spansql.ID) (*Column, bool)

Jump to

Keyboard shortcuts

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