Toggle - @mvdlei/pg-toggle
The pg-toggle
package provides a simple feature toggle implementation with PostgreSQL as the backend.
Installation
Dependencies
The pg-toggle
package depends on the following packages:
@mvdlei/retry
drizzle-orm
postgres-js
Example
API Reference
IToggle
The IToggle
interface defines the contract for the Toggle class.
create<T extends Record<string, boolean>>(toggles: T): Promise<T & Record<string, boolean>>
Create a set of toggles in the database.
toggles
: An object with toggle names as keys and boolean values indicating the toggle status.
get(name: string): Promise<boolean>
Get the status of a toggle by name.
name
: The name of the toggle.
set(name: string, enabled: boolean): Promise<boolean>
Set the status of a toggle by name. Updates if the toggle exists, creates it otherwise.
name
: The name of the toggle.enabled
: The new status of the toggle.
Toggle
Class
The Toggle
class implements the IToggle
interface.
Toggle.init(options: IClientOptions): Promise<IToggle>
Static method to initialize a new Toggle
instance with the provided PostgreSQL connection options.
options
: PostgreSQL connection options.
This method will also create the necessary tables if they don't exist.
Tables are created by the
drizzle-orm
package.