-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapability.go
More file actions
56 lines (49 loc) · 2.33 KB
/
Copy pathcapability.go
File metadata and controls
56 lines (49 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package liteorm
import (
"context"
"time"
)
// Capability interfaces are demand-driven: a backend implements one only when it
// can, and the front-ends type-assert for it and fall back otherwise. SQLite and
// MySQL implement LastInsertIder; the Postgres backend implements BulkInserter
// (native COPY) and adds LISTEN/NOTIFY. RETURNING/OUTPUT is reached directly via
// QueryContext, gated by the dialect's Feature bits, so it needs no interface.
// LastInsertIder is implemented by backends whose driver returns a usable
// last-insert id (SQLite, MySQL). Postgres/MSSQL use RETURNING/OUTPUT instead.
type LastInsertIder interface {
LastInsertId() (int64, error)
}
// RowSource is liteorm's driver-neutral mirror of a bulk row stream (pgx's
// CopyFromSource shape, owned by liteorm so the driver type never leaks).
type RowSource interface {
Next() bool
Values() ([]any, error)
Err() error
}
// BulkInserter is the bulk-insert fast path: the Postgres backend implements it
// with native COPY. Where a backend does not, the query layer falls back to
// chunked multi-row VALUES.
type BulkInserter interface {
CopyFrom(ctx context.Context, table string, columns []string, src RowSource) (int64, error)
}
// PoolStats is liteorm's driver-neutral mirror of database/sql.DBStats, so the
// public surface reports connection-pool health without binding callers to
// database/sql (a backend may be pgx-based). Fields match DBStats one-for-one.
type PoolStats struct {
MaxOpenConnections int // configured max; 0 = unlimited
OpenConnections int // in use + idle
InUse int // currently in use
Idle int // idle in the pool
WaitCount int64 // total connections waited for
WaitDuration time.Duration // total time blocked waiting for a connection
MaxIdleClosed int64 // closed due to SetMaxIdleConns
MaxIdleTimeClosed int64 // closed due to SetConnMaxIdleTime
MaxLifetimeClosed int64 // closed due to SetConnMaxLifetime
}
// StatsProvider is implemented by backends whose driver exposes connection-pool
// statistics — every database/sql-based backend (SQLite, MySQL, MSSQL) and the
// pgx-pool Postgres backend. DB.Stats() type-asserts for it and reports whether
// stats are available.
type StatsProvider interface {
Stats() PoolStats
}