sqldb

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DatabaseParser = &resourceparser.Parser{
	Name: "SQL Database",

	InterestingSubdirs: []string{"migrations"},
	Run: func(p *resourceparser.Pass) {
		migrationDir := p.Pkg.FSPath.Join("migrations")
		migrations, err := parseMigrations(p.Pkg, migrationDir)
		if err != nil {

			if !pkgIsLikelyService(p.Pkg) {
				return
			}

			p.Errs.Add(errUnableToParseMigrations.Wrapping(err))
			return
		} else if len(migrations) == 0 {
			return
		}

		if !pkgIsLikelyService(p.Pkg) {
			return
		}

		res := &Database{
			Pkg:          p.Pkg,
			Name:         p.Pkg.Name,
			MigrationDir: migrationDir,
			Migrations:   migrations,
		}
		p.RegisterResource(res)
		p.AddImplicitBind(res)
	},
}
View Source
var NamedParser = &resourceparser.Parser{
	Name: "Named SQL Database",

	InterestingImports: []paths.Pkg{"encore.dev/storage/sqldb"},
	Run: func(p *resourceparser.Pass) {
		name := pkginfo.QualifiedName{Name: "Named", PkgPath: "encore.dev/storage/sqldb"}

		spec := &parseutil.ReferenceSpec{
			Parse:       parseNamedSQLDB,
			MinTypeArgs: 0,
			MaxTypeArgs: 0,
		}

		parseutil.FindPkgNameRefs(p.Pkg, []pkginfo.QualifiedName{name}, func(file *pkginfo.File, name pkginfo.QualifiedName, stack []ast.Node) {
			parseutil.ParseReference(p, spec, parseutil.ReferenceData{
				File:         file,
				Stack:        stack,
				ResourceFunc: name,
			})
		})
	},
}

Functions

func ComputeImplicitUsage

func ComputeImplicitUsage(errs *perr.List, pkgs []*pkginfo.Package, binds []resource.Bind) []usage.Expr

ComputeImplicitUsage computes the implicit usage of SQLDB resources via package-level sqldb.{Query,QueryRow,Exec,etc} calls.

func ResolveDatabaseUsage

func ResolveDatabaseUsage(data usage.ResolveData, db *Database) usage.Usage

Types

type Database

type Database struct {
	Pkg          *pkginfo.Package
	Name         string // The database name
	MigrationDir paths.FS
	Migrations   []MigrationFile
}

func (*Database) End

func (d *Database) End() token.Pos

func (*Database) Kind

func (d *Database) Kind() resource.Kind

func (*Database) Package

func (d *Database) Package() *pkginfo.Package

func (*Database) Pos

func (d *Database) Pos() token.Pos

func (*Database) ResourceName

func (d *Database) ResourceName() string

type DatabaseUsage

type DatabaseUsage struct {
	usage.Base
}

type MigrationFile

type MigrationFile struct {
	Filename    string
	Number      int
	Description string
}

Jump to

Keyboard shortcuts

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