gws.plugin.postgres.storage_provider

PostgreSQL storage provider.

Source code: gws.plugin.postgres.storage_provider

Module Contents

class gws.plugin.postgres.storage_provider.Config(*args, **kwargs)

Bases: gws.Config

Storage provider that keeps saved user data in a PostgreSQL table.

dbUid: str | None

UID of the database provider.

tableName: str

Table for the stored records.

class gws.plugin.postgres.storage_provider.Object

Bases: gws.StorageProvider

Storage provider that keeps records in a PostgreSQL table.

db: gws.plugin.postgres.provider.Object

Database provider.

tableName: str

Table for the stored records.

configure()

Configuration hook.

Called when the node is initialized. Raising an exception here aborts the creation of the node.

configure_provider()

Set the database provider from dbUid, or the first postgres provider.

Returns:

True if a provider was set.

Raises:

gws.Error – If no provider is found.

configure_table()

Set the table name from the configuration and check that the table exists.

The table must have the columns given in TABLE_DDL.

Raises:

gws.ConfigurationError – If the table does not exist.

delete(category, name)

Delete a record.

Parameters:
  • category – Category name.

  • name – Record name.

list_names(category)

List the record names in a category.

Parameters:

category – Category name.

Returns:

Record names.

read(category, name)

Read a record.

Parameters:
  • category – Category name.

  • name – Record name.

Returns:

The record, or None if not found.

write(category, name, data, user_uid)

Create a record or update an existing one.

Parameters:
  • category – Category name.

  • name – Record name.

  • data – Serialized record data.

  • user_uid – Uid of the user who writes the record.

gws.plugin.postgres.storage_provider.TABLE_DDL = Multiline-String
Show Value
"""
    CREATE TABLE IF NOT EXISTS {table_name} (
        category    TEXT NOT NULL,
        name        TEXT NOT NULL,
        user_uid    TEXT,
        data        TEXT,
        created     TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
        updated     TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
        PRIMARY KEY (category, name)
    )
"""

DDL of the storage table; {table_name} is the table name. The provider does not create the table.