sql

package
v3.0.0-...-7f0c83d Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 11 Imported by: 0

README

SQL Driver for Casbin Watcher

This directory contains the SQL driver for casbin-watcher, providing support for MySQL and PostgreSQL ( including MariaDB, which uses the MySQL driver).

This driver uses the watermill-sql library to provide a Pub/Sub mechanism over a SQL database.

Supported Databases

  • MySQL (Driver name: mysql)
  • PostgreSQL (Driver name: postgres)
  • MariaDB (Driver name: mariadb, uses the mysql driver)

Note: For SQLite support, please use the standalone sqlite driver in the parent directory.

Configuration

The driver is configured using a database connection URL. The scheme of the URL determines which database driver is used.

MySQL / MariaDB

The driver will automatically reconstruct the DSN from the URL.

URL Format:

mysql://user:password@tcp(host:port)/dbname?query_params

or

mariadb://user:password@tcp(host:port)/dbname?query_params

Example:

mysql://root:password@tcp(127.0.0.1:3306)/casbin
PostgreSQL

For PostgreSQL, the URL is passed directly as the DSN.

URL Format:

postgres://user:password@host:port/dbname?query_params

Example:

postgres://user:password@localhost:5432/casbin?sslmode=disable
Table Creation

The driver uses watermill's schema adapters to automatically create the necessary tables (e.g., watermill_messages, watermill_offsets) for storing messages and offsets if they do not already exist.

Usage Example

PostgreSQL
postgres://user:pass@localhost:5432/casbin_db?sslmode=disable
MySQL
mysql://root:password@tcp(127.0.0.1:3306)/casbin

The topic for policy updates is taken from the URL path or defaults to casbin-policy-updates. You can also specify it using the WithTopic option.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver struct{}

Driver implements the watcher.Driver interface for SQL databases.

func (*Driver) NewPubSub

func (d *Driver) NewPubSub(_ context.Context, u *url.URL, logger watermill.LoggerAdapter) (watcher.PubSub, error)

NewPubSub creates a new PubSub for SQL.

Jump to

Keyboard shortcuts

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