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) ResourceName ¶
type DatabaseUsage ¶
type MigrationFile ¶
Click to show internal directories.
Click to hide internal directories.