MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / beginWorkspaceGroupWrite

Method beginWorkspaceGroupWrite

internal/store/workspace_groups.go:91–106  ·  view source on GitHub ↗

beginWorkspaceGroupWrite serializes writes for one user before touching group rows. SQLite uses BEGIN IMMEDIATE; Postgres takes the strongest required user lock first, so cap and name checks cannot race.

(ctx context.Context, userID string)

Source from the content-addressed store, hash-verified

89// group rows. SQLite uses BEGIN IMMEDIATE; Postgres takes the strongest
90// required user lock first, so cap and name checks cannot race.
91func (s *Store) beginWorkspaceGroupWrite(ctx context.Context, userID string) (*sql.Tx, error) {
92 tx, err := s.db.BeginTx(ctx, nil)
93 if err != nil {
94 return nil, err
95 }
96 query := `SELECT id FROM users WHERE id = ?`
97 if s.dialect.Driver() == DriverPostgres {
98 query += ` FOR NO KEY UPDATE`
99 }
100 var id string
101 if err := tx.QueryRowContext(ctx, s.q(query), userID).Scan(&id); err != nil {
102 _ = tx.Rollback()
103 return nil, err
104 }
105 return tx, nil
106}
107
108func (s *Store) workspaceGroupNameAvailable(ctx context.Context, tx *sql.Tx, userID, id, name string) error {
109 // EqualFold also handles Unicode names on SQLite, whose lower() folds ASCII.

Calls 6

qMethod · 0.95
QueryRowContextMethod · 0.80
RollbackMethod · 0.80
DriverMethod · 0.65
ScanMethod · 0.65
BeginTxMethod · 0.45

Tested by

no test coverage detected