Go - NewSqlDatabase()

Creates a reference to a SQL database.

import (
"github.com/nitrictech/go-sdk/nitric"
)
db := nitric.NewSqlDatabase("my-database")

Parameters

  • Name
    name
    Required
    Required
    Type
    string
    Description

    The unique name of this database within the project.

  • Name
    options
    Optional
    Optional
    Type
    ...sqlDatabaseOption
    Description

    Additional options for the SQL Database. See below.

SQL Database options

  • Name
    WithMigrationsPath()
    Optional
    Optional
    Type
    sqlDatabaseOption
    Description
    • Name
      path
      Required
      Required
      Type
      string
      Description

      Points to the location of migration files, prefixed with file://, or a migration dockerfile, prefixed with dockerfile://.

Examples

Create a reference to a database

import (
"github.com/nitrictech/go-sdk/nitric"
)
db := nitric.NewSqlDatabase("my-database")

With a migrations directory

import (
"github.com/nitrictech/go-sdk/nitric"
"github.com/nitrictech/go-sdk/nitric/sql"
)
func main() {
db := nitric.NewSqlDatabase("my-database", sql.WithMigrationsPath("file://migrations/my-database"))
nitric.Run()
}

With a migrations dockerfile

import (
"github.com/nitrictech/go-sdk/nitric"
"github.com/nitrictech/go-sdk/nitric/sql"
)
func main() {
db := nitric.NewSqlDatabase("my-database", sql.WithMigrationsPath("dockerfile://migrations.dockerfile"))
nitric.Run()
}

See also

Last updated on Dec 5, 2024