sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
11.54k stars 741 forks source link

Managed databases with any accessible server #3415

Closed kyleconroy closed 3 weeks ago

kyleconroy commented 3 weeks ago

Managed databases only work using database servers hosted by sqlc Cloud. I'm going to add support for using managed databases with any database server you can access.

Database servers will be configured in a separate servers collection in the configuration file.

version: "2"
servers:
  - uri: postgres://localhost:5432/postgres

Each entry will have a mandatory uri field and an optional name. I may add an optional engine field if the URI scheme isn't enough to infer the engine type.

version: "2"
servers:
  - uri: postgres://localhost:5432/postgres
sql:
  - engine: "postgresql"
    queries: "query.sql"
    schema: "schema.sql"
    database:
      managed: true
    gen:
      go:
        package: "tutorial"
        out: "tutorial"
        sql_package: "pgx/v5"

When using a database server not hosted by sqlc Cloud, sqlc will automatically create databases as needed based on the schema for the associated query set. All operations against these databases will be read-only, so they can be created once and re-used.