database

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package database 管理 Pixiv / FANBOX 鉴权状态的单一 SQLite 数据库。 它只保存鉴权数据与 Pixiv account-pool 租约状态,不保存普通配置、下载 archive、缓存、请求日志或浏览器 profile。

Index

Constants

View Source
const ApplicationID = 0x50495843

ApplicationID 是数据库文件的固定 SQLite application_id(ASCII "PIXC")。

Variables

This section is empty.

Functions

func CurrentVersion

func CurrentVersion() int

CurrentVersion 返回 binary 所知的最新 schema 版本。

func DatabasePath

func DatabasePath(appDataDir string) string

DatabasePath 返回鉴权数据库在本机私有目录下的固定路径。

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

func Open

func Open(appDataDir string) (*DB, error)

Open 打开或创建 appDataDir 下的鉴权数据库,收紧目录与文件权限,设置连接 pragma,并应用全部 schema migration。调用方必须 Close。

func (*DB) Close

func (d *DB) Close() error

Close 关闭底层数据库。

func (*DB) DB

func (d *DB) DB() *sql.DB

DB 返回底层 *sql.DB,供 repository 与测试使用。

func (*DB) Freeze

func (d *DB) Freeze(ctx context.Context, userID, frozenUntil int64) error

Freeze 记录一个账号的有效冻结时间。

func (*DB) GetFanbox

func (d *DB) GetFanbox(ctx context.Context, userID int64) (accountfanbox.Account, error)

GetFanbox 返回指定 user_id 的 FANBOX 账号;不存在返回 ErrNotFound。

func (*DB) GetPixiv

func (d *DB) GetPixiv(ctx context.Context, userID int64) (accountpixiv.Account, error)

GetPixiv 返回指定 user_id 的 Pixiv 账号;不存在返回 ErrNotFound。

func (*DB) ListFanbox

func (d *DB) ListFanbox(ctx context.Context) ([]accountfanbox.Account, error)

ListFanbox 返回全部 FANBOX 账号,按 sort_order 升序。

func (*DB) ListPixiv

func (d *DB) ListPixiv(ctx context.Context) ([]accountpixiv.Account, error)

ListPixiv 返回全部 Pixiv 账号,按 sort_order 升序。

func (*DB) ListPixivPoolStatus

func (d *DB) ListPixivPoolStatus(ctx context.Context, now int64) (accountpixiv.PoolStatus, error)

ListPixivPoolStatus 返回 non-secret 调度状态,并在同一个事务中清理已过期冻结。

func (*DB) Path

func (d *DB) Path() string

Path 返回数据库文件路径。

func (*DB) RemoveFanbox

func (d *DB) RemoveFanbox(ctx context.Context, userID int64) error

RemoveFanbox 删除一个 FANBOX 账号。

func (*DB) RemovePixiv

func (d *DB) RemovePixiv(ctx context.Context, userID int64) error

RemovePixiv 删除一个 Pixiv 账号,其 pool 标记随之自然删除。

func (*DB) RotateFanboxSession

func (d *DB) RotateFanboxSession(ctx context.Context, userID, expectedRevision int64, session []byte, validatedAt int64) error

RotateFanboxSession 更新 FANBOX session 并递增 credential_revision。

func (*DB) RotatePixivCredentials

func (d *DB) RotatePixivCredentials(ctx context.Context, userID, expectedRevision int64, refreshToken []byte) error

RotatePixivCredentials 提交一次 refresh token rotation:更新 token 并递增 credential_revision。

func (*DB) SaveFanboxCredential

func (d *DB) SaveFanboxCredential(ctx context.Context, account accountfanbox.Account) error

SaveFanboxCredential 保存一次已验证的 FANBOX credential。 新账号固定从 revision 1 开始;已有账号在 SQL 内递增 revision。

func (*DB) SavePixivCredential

func (d *DB) SavePixivCredential(ctx context.Context, account accountpixiv.Account) error

SavePixivCredential 保存一次已验证的 Pixiv credential。 新账号固定从 revision 1 开始;已有账号在 SQL 内递增 revision,不能由调用方回退。

func (*DB) SavePixivCredentials

func (d *DB) SavePixivCredentials(ctx context.Context, accounts []accountpixiv.Account) error

SavePixivCredentials 在一个事务中保存一组首次导入的 Pixiv credentials。 迁移调用它保证任一账号失败时不会留下部分提交。

func (*DB) SelectPixiv

func (d *DB) SelectPixiv(ctx context.Context, now int64, attemptedUserIDs []int64, chooser accountpixiv.Chooser) (accountpixiv.Account, error)

SelectPixiv 在一个短事务内加载候选快照,并把纯 chooser 的结果验证后提交 为 pool_last_selected marker。chooser 不接触 SQL;attemptedUserIDs 只属于当前 operation,不会写入数据库;过期冻结在选择时清理。

func (*DB) SetAllPixivSchedulable

func (d *DB) SetAllPixivSchedulable(ctx context.Context, schedulable bool) error

SetAllPixivSchedulable 在一个事务内更新当前所有 Pixiv 账号。

func (*DB) SetPixivSchedulable

func (d *DB) SetPixivSchedulable(ctx context.Context, userIDs []int64, schedulable bool) error

func (*DB) UpdatePixivMetadata

func (d *DB) UpdatePixivMetadata(ctx context.Context, userID int64, username string, premiumStatus *bool, premiumCheckedAt *int64) error

UpdatePixivMetadata 更新会员快照等非 credential 元数据,不改变 revision 或 token。

Jump to

Keyboard shortcuts

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