Skip to main content

Database Plugin

Lynx does not currently expose one generic lynx.db plugin. The real database entry points are the concrete SQL plugins: MySQL, PostgreSQL, and MSSQL, all built on top of lynx-sql-sdk.

Runtime Facts

DatabaseGo moduleConfig prefixRuntime plugin nameCommon public APIs
MySQLgithub.com/go-lynx/lynx-mysqllynx.mysqlmysql.clientGetDB(), GetProvider(), GetDriver()
PostgreSQLgithub.com/go-lynx/lynx-pgsqllynx.pgsqlpgsql.clientGetDB(), GetProvider(), GetDriver()
MSSQLgithub.com/go-lynx/lynx-mssqllynx.mssqlmssql.clientGetDB(), GetProvider()

Shared SQL Behavior

These concrete plugins all inherit the SQL SDK runtime capabilities:

  • startup connection and validation
  • connection retry
  • pool monitoring
  • health checks
  • auto-reconnect
  • warmup
  • slow-query monitoring
  • leak detection

So the right way to think about the SQL stack is "concrete DB plugin plus shared SQL runtime layer", not "one abstract db plugin".

MySQL Example

lynx:
mysql:
driver: mysql
source: "root:123@tcp(127.0.0.1:3306)/demo?parseTime=True"
min_conn: 10
max_conn: 50
max_idle_time: 30s

What The Official Template Uses

The official template currently chooses MySQL first, not a fake generic db block:

lynx:
mysql:
driver: mysql
source: "lynx:lynx123456@tcp(127.0.0.1:3306)/lynx_test?charset=utf8mb4&parseTime=True&loc=Local"
min_conn: 10
max_conn: 10

That matters because many older docs implied there was one abstract database plugin. The real project template confirms the opposite: pick a concrete SQL plugin such as lynx.mysql, then consume its provider and runtime-owned pool.

PostgreSQL Example

lynx:
pgsql:
driver: postgres
source: "postgres://postgres:123@127.0.0.1:5432/demo?sslmode=disable"
min_conn: 10
max_conn: 50

How To Consume It

import mysql "github.com/go-lynx/lynx-mysql"

db, err := mysql.GetDB()
provider := mysql.GetProvider()
driver, err := mysql.GetDriver()

Use the provider form for long-lived components when auto-reconnect is enabled, because caching an old *sql.DB or driver can become invalid after pool replacement.

This is also what lynx-layout/internal/data/data.go does. It calls lynx-mysql.GetProvider() and derives the Ent driver from that stable provider instead of caching a one-time DB handle forever.