AS AgentScopeAPI 手册 / API Reference

PostgresBaseStore

public class PostgresBaseStore implements BaseStore
源码Source io/agentscope/extensions/postgresql/store/PostgresBaseStore.java:73–449

Postgres 基类存储,负责持久化与读取数据。位于 io.agentscope.extensions.postgresql.store 包,实现 BaseStore。核心成员包括 builder、get、put、putIfVersion、search、delete。

PostgreSQL-backed BaseStore.

Schema

`CREATE TABLE agentscope_store (
namespace_path VARCHAR(2048) NOT NULL,
item_key VARCHAR(255) NOT NULL,
value_json TEXT NOT NULL,
version BIGINT NOT NULL,
updated_at BIGINT NOT NULL,
PRIMARY KEY (namespace_path, item_key)
)
`

The optional Builder#initializeSchema(true) flag runs CREATE TABLE IF NOT EXISTS on construction.

Namespace encoding

To preserve the prefix-search behaviour of InMemoryStore, the namespace components are joined with the ASCII unit-separator 0x1F and stored with a trailing separator. Searching by namespace [a, b] translates into WHERE namespace_path LIKE 'ab%' ESCAPE '!', which matches both that exact namespace and any deeper sub-namespace. Namespace segments that contain 0x1F are rejected.

CAS

#putIfVersion uses a single-statement conditional UPDATE keyed on version. The expectedVersion == 0 case issues an INSERT and treats a primary-key conflict as a failed CAS. Both paths are atomic without additional locking, so the store is safe to share among multiple JVMs writing to the same database.

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Builder类class
`PostgresBaseStore`的构建器。
Builder for `PostgresBaseStore`.

字段摘要Field Summary

字段Field类型Type说明Description
DEFAULT_TABLE_NAME
staticfinal
String
默认 TABLE 名称字段。
Default table name used when the builder is not customised.

方法摘要Method Summary

方法Method说明Description
public static Builder builder(DataSource dataSource)
static
创建构建器用于`PostgresBaseStore`。
Creates a builder for `PostgresBaseStore`.
public StoreItem get(List<String> namespace, String key)
按条件读取数据。
Performs the get operation.
public void put(List<String> namespace, String key, Map<String, Object> value)
执行 `put` 方法。
Performs the put operation.
public boolean putIfVersion(List<String> namespace, String key, Map<String, Object> value, long expectedVersion)
执行 `putIfVersion` 方法。
Performs the put if version operation.
public List<StoreItem> search(List<String> namespace, int limit, int offset)
执行搜索相关操作。
Performs the search operation.
public void delete(List<String> namespace, String key)
删除数据。
Performs the delete operation.

字段详情Field Detail

DEFAULT_TABLE_NAME

public static final String DEFAULT_TABLE_NAME
staticfinal

默认 TABLE 名称字段。声明为 public static final String DEFAULT_TABLE_NAME。

Default table name used when the builder is not customised.

源码Source io/agentscope/extensions/postgresql/store/PostgresBaseStore.java:85

方法详情Method Detail

builder

public static Builder builder(DataSource dataSource)
static

创建构建器用于PostgresBaseStore。

Creates a builder for PostgresBaseStore.

参数Parameters
名称Name类型Type说明Description
dataSourceDataSource数据来源(类型 `DataSource`)。The data source.
返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/extensions/postgresql/store/PostgresBaseStore.java:171–173

get

public StoreItem get(List<String> namespace, String key)

按条件读取数据。

Performs the get operation.

参数Parameters
名称Name类型Type说明Description
namespaceList<String>命名空间(类型 `List`)。The namespace.
keyString键(类型 `String`)。The key.
返回Returns StoreItem
返回StoreItem。Returns store item.
源码Source io/agentscope/extensions/postgresql/store/PostgresBaseStore.java:197–216

put

public void put(List<String> namespace, String key, Map<String, Object> value)

执行 put 方法。

Performs the put operation.

参数Parameters
名称Name类型Type说明Description
namespaceList<String>命名空间(类型 `List`)。The namespace.
keyString键(类型 `String`)。The key.
valueMap<String, Object>值(类型 `Map`)。The value.
源码Source io/agentscope/extensions/postgresql/store/PostgresBaseStore.java:218–233

putIfVersion

public boolean putIfVersion(List<String> namespace, String key, Map<String, Object> value, long expectedVersion)

执行 putIfVersion 方法。

Performs the put if version operation.

参数Parameters
名称Name类型Type说明Description
namespaceList<String>命名空间(类型 `List`)。The namespace.
keyString键(类型 `String`)。The key.
valueMap<String, Object>值(类型 `Map`)。The value.
expectedVersionlongexpected 版本(类型 `long`)。The expected version.
返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/extensions/postgresql/store/PostgresBaseStore.java:235–275

delete

public void delete(List<String> namespace, String key)

删除数据。

Performs the delete operation.

参数Parameters
名称Name类型Type说明Description
namespaceList<String>命名空间(类型 `List`)。The namespace.
keyString键(类型 `String`)。The key.
源码Source io/agentscope/extensions/postgresql/store/PostgresBaseStore.java:304–316

嵌套类详情Nested Class Detail

Builder

public static final class Builder

PostgresBaseStore的构建器。位于 io.agentscope.extensions.postgresql.store 包。核心成员包括 objectMapper、schemaName、tableName、initializeSchema、build。

Builder for PostgresBaseStore.

基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.