Documentation
¶
Overview ¶
Package pgstore keeps collab documents in PostgreSQL.
It implements github.com/go-crdt/collab.Store over a plain *sql.DB and brings no driver of its own, so the caller chooses one — pgx, lib/pq, or a pool wrapped to look like either. That also keeps this package's dependencies to the standard library.
db, err := sql.Open("pgx", os.Getenv("DATABASE_URL"))
store, err := pgstore.New(db)
if err := store.Migrate(ctx); err != nil { … }
srv := collab.NewServer(collab.Config{Store: store})
A document is stored as one row holding its whole snapshot, which is what the [collab.Store] contract asks for: snapshots are self-contained, so a document restored from one can still serve a participant that has been away. The cost is that saving writes the whole document, so a server holding very large ones should call [collab.Server.Flush] on a timer rather than after every change.
Index ¶
Constants ¶
const DefaultTable = "collab_documents"
DefaultTable is the table documents are kept in.
Variables ¶
var ErrInvalidTable = errors.New("pgstore: table name must be a plain identifier")
ErrInvalidTable reports a table name that is not a plain SQL identifier. Table names cannot be passed as query parameters, so they are checked rather than trusted.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Store)
An Option adjusts a Store.
func WithTable ¶
WithTable puts the documents in a table other than DefaultTable. The name must be a plain identifier: a letter or underscore followed by letters, digits or underscores.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
A Store keeps documents in one table. It is safe for concurrent use, as *sql.DB is.
func (*Store) Documents ¶
Documents returns the names of the documents held, ordered, which is what a caller needs to inspect or migrate a store.
func (*Store) Load ¶
Load returns the snapshot for a document, or nil if there is none yet. A document nobody has written is not an error; it is a new document.