sqldb

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: MPL-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

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

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

		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,
			})
		})
	},
}
View Source
var (
	ErrDuplicateNames = errRange.New(
		"Duplicate Databases",
		"Multiple databases with the same name were found. Database names must be unique.",
	)
)
View Source
var MigrationParser = &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
		}

		relMigrationDir, err := filepath.Rel(p.MainModuleDir.ToIO(), migrationDir.ToIO())
		if err != nil || !filepath.IsLocal(relMigrationDir) {
			p.Errs.Add(errMigrationsNotInMainModule)
			return
		}

		res := &Database{
			Pkg:          p.Pkg,
			Name:         p.Pkg.Name,
			MigrationDir: paths.MainModuleRelSlash(filepath.ToSlash(relMigrationDir)),
			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 {
	AST          *ast.CallExpr
	Pkg          *pkginfo.Package
	Name         string // The database name
	Doc          string
	File         option.Option[*pkginfo.File]
	MigrationDir paths.MainModuleRelSlash
	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

func (*Database) SortKey added in v1.16.3

func (d *Database) SortKey() string

type DatabaseUsage

type DatabaseUsage struct {
	usage.Base
}

type MigrationFile

type MigrationFile struct {
	Filename    string
	Number      uint64
	Description string
}

Jump to

Keyboard shortcuts

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