pico
created pr with
97.1
added 97.2
1: fdc255e = 1: fdc255e refactor: remove unused db methods
2: 3f855f6 = 2: 3f855f6 chore: add tests for postgres db impl
3: 7cd29a6 = 3: 7cd29a6 refactor: use sqlx interface
4: acd449e = 4: acd449e chore: add db tags
5: f6ed0d7 = 5: f6ed0d7 refactor: use sqlx
6: 29035c6 = 6: 29035c6 refactor: replace custom sql functions with sqlx
7: d4ea6d9 = 7: d4ea6d9 refactor: inline all sql queries
-: ------- > 8: 4bd37ed refactor: use `select * from` where possible
cmds
checkout latest patchset:
ssh pr.pico.sh print 97 | git am -3checkout any patchset in a patch request:
ssh pr.pico.sh print 97.[rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 97
Patchset
97.2
→ refactor: remove unused db methods
Eric Bower
chore: add tests for postgres db impl
2025-12-18T03:03:10ZEric Bower
refactor: use sqlx interface
2025-12-18T03:17:57ZEric Bower
chore: add db tags
2025-12-18T03:27:57ZEric Bower
refactor: use sqlx
2025-12-18T03:31:25ZEric Bower
refactor: replace custom sql functions with sqlx
2025-12-18T03:43:01ZEric Bower
refactor: inline all sql queries
2025-12-18T03:57:00ZEric Bower
refactor: use `select * from` where possible
2025-12-18T04:02:50ZEric Bower
2025-12-18T04:33:58Z
refactor: remove unused db methods
Eric Bower
2025-12-18T03:03:10ZSemantic diff summary
5 added,
17 modified,
0 signature changed,
28 removed
across 3 analyzed files
(1 file skipped: unsupported file type)
pkg/db/postgres/storage.go
-
chunklines 29-34modified -
chunklines 51-56modified -
chunklines 140-145modified -
chunklines 147-153modified -
chunklines 184-189modified -
chunklines 202-212modified -
method_declarationRegisterUsermodified -
method_declarationInsertPublicKeymodified -
method_declarationRemoveUsersremoved -
method_declarationUpdatePublicKeymodified -
method_declarationfindPublicKeyForKeyadded -
method_declarationFindPublicKeyForKeyremoved -
method_declarationfindPublicKeyadded -
method_declarationFindPublicKeyremoved -
method_declarationFindPostsBeforeDateremoved -
function_declarationFindUsersWithPostmodified -
function_declarationFindUserForKeymodified -
method_declarationFindUserByPubkeymodified -
method_declarationvalidateNameadded -
method_declarationValidateNameremoved -
method_declarationfindUserForNameAndKeyadded -
method_declarationFindUserForNameAndKeyremoved -
method_declarationSetUserNameremoved -
method_declarationFindAllUpdatedPostsremoved -
method_declarationFindUpdatedPostsForUserremoved -
method_declarationFindTagsForUserremoved -
method_declarationFindTagsForPostremoved -
method_declarationFindTotalSizeForUserremoved -
method_declarationUpsertTokenmodified -
method_declarationfindTokenByNameadded -
method_declarationFindTokenByNameremoved
pkg/db/stub/stub.go
-
method_declarationFindPublicKeyForKeyremoved -
method_declarationFindPublicKeyremoved -
method_declarationRemoveUsersremoved -
method_declarationFindPostsBeforeDateremoved -
method_declarationValidateNameremoved -
method_declarationFindUserForNameAndKeyremoved -
method_declarationSetUserNameremoved -
method_declarationFindAllUpdatedPostsremoved -
method_declarationFindUpdatedPostsForUserremoved -
method_declarationFindTagsForPostremoved -
method_declarationFindTotalSizeForUserremoved -
method_declarationInsertProjectremoved -
method_declarationUpdateProjectremoved -
method_declarationFindTokenByNameremoved -
method_declarationFindTagsForUserremoved
+1
-14
pkg/db/db.go
#
| ... | ... | @@ -389,28 +389,21 @@ var DenyList = []string{ | |
| 389 | 389 | ||
| 390 | 390 | type DB interface { | |
| 391 | 391 | RegisterUser(name, pubkey, comment string) (*User, error) | |
| 392 | - | RemoveUsers(userIDs []string) error | |
| 393 | 392 | UpdatePublicKey(pubkeyID, name string) (*PublicKey, error) | |
| 394 | 393 | InsertPublicKey(userID, pubkey, name string, tx *sql.Tx) error | |
| 395 | - | FindPublicKeyForKey(pubkey string) (*PublicKey, error) | |
| 396 | - | FindPublicKey(pubkeyID string) (*PublicKey, error) | |
| 397 | 394 | FindKeysForUser(user *User) ([]*PublicKey, error) | |
| 398 | 395 | RemoveKeys(pubkeyIDs []string) error | |
| 399 | 396 | ||
| 400 | 397 | FindUsers() ([]*User, error) | |
| 401 | 398 | FindUserByName(name string) (*User, error) | |
| 402 | - | FindUserForNameAndKey(name string, pubkey string) (*User, error) | |
| 403 | 399 | FindUserForKey(name string, pubkey string) (*User, error) | |
| 404 | 400 | FindUserByPubkey(pubkey string) (*User, error) | |
| 405 | 401 | FindUser(userID string) (*User, error) | |
| 406 | - | ValidateName(name string) (bool, error) | |
| 407 | - | SetUserName(userID string, name string) error | |
| 408 | 402 | ||
| 409 | 403 | FindUserForToken(token string) (*User, error) | |
| 410 | 404 | FindTokensForUser(userID string) ([]*Token, error) | |
| 411 | 405 | InsertToken(userID, name string) (string, error) | |
| 412 | 406 | UpsertToken(userID, name string) (string, error) | |
| 413 | - | FindTokenByName(userID, name string) (string, error) | |
| 414 | 407 | RemoveToken(tokenID string) error | |
| 415 | 408 | ||
| 416 | 409 | FindPosts() ([]*Post, error) |
| ... | ... | @@ -418,13 +411,10 @@ type DB interface { | |
| 418 | 411 | FindPostsForUser(pager *Pager, userID string, space string) (*Paginate[*Post], error) | |
| 419 | 412 | FindAllPostsForUser(userID string, space string) ([]*Post, error) | |
| 420 | 413 | FindUsersWithPost(space string) ([]*User, error) | |
| 421 | - | FindPostsBeforeDate(date *time.Time, space string) ([]*Post, error) | |
| 422 | 414 | FindExpiredPosts(space string) ([]*Post, error) | |
| 423 | - | FindUpdatedPostsForUser(userID string, space string) ([]*Post, error) | |
| 424 | 415 | FindPostWithFilename(filename string, userID string, space string) (*Post, error) | |
| 425 | 416 | FindPostWithSlug(slug string, userID string, space string) (*Post, error) | |
| 426 | 417 | FindPostsForFeed(pager *Pager, space string) (*Paginate[*Post], error) | |
| 427 | - | FindAllUpdatedPosts(pager *Pager, space string) (*Paginate[*Post], error) | |
| 428 | 418 | InsertPost(post *Post) (*Post, error) | |
| 429 | 419 | UpdatePost(post *Post) (*Post, error) | |
| 430 | 420 | RemovePosts(postIDs []string) error |
| ... | ... | @@ -433,9 +423,6 @@ type DB interface { | |
| 433 | 423 | FindUserPostsByTag(pager *Pager, tag, userID, space string) (*Paginate[*Post], error) | |
| 434 | 424 | FindPostsByTag(pager *Pager, tag, space string) (*Paginate[*Post], error) | |
| 435 | 425 | FindPopularTags(space string) ([]string, error) | |
| 436 | - | FindTagsForPost(postID string) ([]string, error) | |
| 437 | - | FindTagsForUser(userID string, space string) ([]string, error) | |
| 438 | - | ||
| 439 | 426 | ReplaceAliasesForPost(aliases []string, postID string) error | |
| 440 | 427 | ||
| 441 | 428 | InsertVisit(view *AnalyticsVisits) error |
| ... | ... | @@ -447,7 +434,7 @@ type DB interface { | |
| 447 | 434 | FindFeature(userID string, feature string) (*FeatureFlag, error) | |
| 448 | 435 | FindFeaturesForUser(userID string) ([]*FeatureFlag, error) | |
| 449 | 436 | HasFeatureForUser(userID string, feature string) bool | |
| 450 | - | FindTotalSizeForUser(userID string) (int, error) | |
| 437 | + | ||
| 451 | 438 | InsertFeature(userID, name string, expiresAt time.Time) (*FeatureFlag, error) | |
| 452 | 439 | RemoveFeature(userID, names string) error | |
| 453 | 440 |
+14
-176
pkg/db/postgres/storage.go
#
| ... | ... | @@ -29,12 +29,6 @@ var ( | |
| 29 | 29 | FROM posts | |
| 30 | 30 | LEFT JOIN app_users ON app_users.id = posts.user_id`, SelectPost) | |
| 31 | 31 | ||
| 32 | - | sqlSelectPostsBeforeDate = fmt.Sprintf(` | |
| 33 | - | SELECT %s | |
| 34 | - | FROM posts | |
| 35 | - | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 36 | - | WHERE publish_at::date <= $1 AND cur_space = $2`, SelectPost) | |
| 37 | - | ||
| 38 | 32 | sqlSelectPostWithFilename = fmt.Sprintf(` | |
| 39 | 33 | SELECT %s, STRING_AGG(coalesce(post_tags.name, ''), ',') tags | |
| 40 | 34 | FROM posts |
| ... | ... | @@ -57,13 +51,6 @@ var ( | |
| 57 | 51 | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 58 | 52 | WHERE posts.id = $1`, SelectPost) | |
| 59 | 53 | ||
| 60 | - | sqlSelectUpdatedPostsForUser = fmt.Sprintf(` | |
| 61 | - | SELECT %s | |
| 62 | - | FROM posts | |
| 63 | - | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 64 | - | WHERE user_id = $1 AND publish_at::date <= CURRENT_DATE AND cur_space = $2 | |
| 65 | - | ORDER BY posts.updated_at DESC`, SelectPost) | |
| 66 | - | ||
| 67 | 54 | sqlSelectExpiredPosts = fmt.Sprintf(` | |
| 68 | 55 | SELECT %s | |
| 69 | 56 | FROM posts |
| ... | ... | @@ -153,7 +140,6 @@ const ( | |
| 153 | 140 | sqlSelectTokenByNameForUser = `SELECT token FROM tokens WHERE user_id = $1 AND name = $2` | |
| 154 | 141 | ||
| 155 | 142 | sqlSelectFeatureForUser = `SELECT id, user_id, payment_history_id, name, data, created_at, expires_at FROM feature_flags WHERE user_id = $1 AND name = $2 ORDER BY expires_at DESC LIMIT 1` | |
| 156 | - | sqlSelectSizeForUser = `SELECT COALESCE(sum(file_size), 0) FROM posts WHERE user_id = $1` | |
| 157 | 143 | ||
| 158 | 144 | sqlSelectPostIdByAliasSlug = `SELECT post_id FROM post_aliases WHERE slug = $1` | |
| 159 | 145 | sqlSelectTagPostCount = ` |
| ... | ... | @@ -161,25 +147,7 @@ const ( | |
| 161 | 147 | FROM posts | |
| 162 | 148 | LEFT JOIN post_tags ON post_tags.post_id = posts.id | |
| 163 | 149 | WHERE hidden = FALSE AND cur_space=$1 and post_tags.name = $2` | |
| 164 | - | sqlSelectPostCount = `SELECT count(id) FROM posts WHERE hidden = FALSE AND cur_space=$1` | |
| 165 | - | sqlSelectAllUpdatedPosts = ` | |
| 166 | - | SELECT | |
| 167 | - | posts.id, | |
| 168 | - | user_id, | |
| 169 | - | filename, | |
| 170 | - | slug, | |
| 171 | - | title, | |
| 172 | - | text, | |
| 173 | - | description, | |
| 174 | - | publish_at, | |
| 175 | - | app_users.name as username, | |
| 176 | - | posts.updated_at, | |
| 177 | - | posts.mime_type | |
| 178 | - | FROM posts | |
| 179 | - | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 180 | - | WHERE hidden = FALSE AND publish_at::date <= CURRENT_DATE AND cur_space = $3 | |
| 181 | - | ORDER BY updated_at DESC | |
| 182 | - | LIMIT $1 OFFSET $2` | |
| 150 | + | sqlSelectPostCount = `SELECT count(id) FROM posts WHERE hidden = FALSE AND cur_space=$1` | |
| 183 | 151 | // add some users to deny list since they are robogenerating a bunch of posts | |
| 184 | 152 | // per day and are creating a lot of noise. | |
| 185 | 153 | sqlSelectPostsByRank = ` |
| ... | ... | @@ -216,13 +184,6 @@ const ( | |
| 216 | 184 | GROUP BY name | |
| 217 | 185 | ORDER BY tally DESC | |
| 218 | 186 | LIMIT 5` | |
| 219 | - | sqlSelectTagsForUser = ` | |
| 220 | - | SELECT name | |
| 221 | - | FROM post_tags | |
| 222 | - | LEFT JOIN posts ON posts.id = post_id | |
| 223 | - | WHERE posts.user_id = $1 AND posts.cur_space = $2 | |
| 224 | - | GROUP BY name` | |
| 225 | - | sqlSelectTagsForPost = `SELECT name FROM post_tags WHERE post_id=$1` | |
| 226 | 187 | sqlSelectFeedItemsByPost = `SELECT id, post_id, guid, data, created_at FROM feed_items WHERE post_id=$1` | |
| 227 | 188 | ||
| 228 | 189 | sqlInsertPost = ` |
| ... | ... | @@ -241,13 +202,11 @@ const ( | |
| 241 | 202 | SET slug = $1, title = $2, text = $3, description = $4, updated_at = $5, publish_at = $6, | |
| 242 | 203 | file_size = $7, shasum = $8, data = $9, hidden = $11, expires_at = $12 | |
| 243 | 204 | WHERE id = $10` | |
| 244 | - | sqlUpdateUserName = `UPDATE app_users SET name = $1 WHERE id = $2` | |
| 245 | 205 | ||
| 246 | 206 | sqlRemoveAliasesByPost = `DELETE FROM post_aliases WHERE post_id = $1` | |
| 247 | 207 | sqlRemoveTagsByPost = `DELETE FROM post_tags WHERE post_id = $1` | |
| 248 | 208 | sqlRemovePosts = `DELETE FROM posts WHERE id = ANY($1::uuid[])` | |
| 249 | 209 | sqlRemoveKeys = `DELETE FROM public_keys WHERE id = ANY($1::uuid[])` | |
| 250 | - | sqlRemoveUsers = `DELETE FROM app_users WHERE id = ANY($1::uuid[])` | |
| 251 | 210 | ||
| 252 | 211 | sqlInsertProject = `INSERT INTO projects (user_id, name, project_dir) VALUES ($1, $2, $3) RETURNING id;` | |
| 253 | 212 | sqlUpdateProject = `UPDATE projects SET updated_at = $3 WHERE user_id = $1 AND name = $2;` |
| ... | ... | @@ -348,7 +307,7 @@ func NewDB(databaseUrl string, logger *slog.Logger) *PsqlDB { | |
| 348 | 307 | ||
| 349 | 308 | func (me *PsqlDB) RegisterUser(username, pubkey, comment string) (*db.User, error) { | |
| 350 | 309 | lowerName := strings.ToLower(username) | |
| 351 | - | valid, err := me.ValidateName(lowerName) | |
| 310 | + | valid, err := me.validateName(lowerName) | |
| 352 | 311 | if !valid { | |
| 353 | 312 | return nil, err | |
| 354 | 313 | } |
| ... | ... | @@ -389,14 +348,8 @@ func (me *PsqlDB) RegisterUser(username, pubkey, comment string) (*db.User, erro | |
| 389 | 348 | return me.FindUserForKey(username, pubkey) | |
| 390 | 349 | } | |
| 391 | 350 | ||
| 392 | - | func (me *PsqlDB) RemoveUsers(userIDs []string) error { | |
| 393 | - | param := "{" + strings.Join(userIDs, ",") + "}" | |
| 394 | - | _, err := me.Db.Exec(sqlRemoveUsers, param) | |
| 395 | - | return err | |
| 396 | - | } | |
| 397 | - | ||
| 398 | 351 | func (me *PsqlDB) InsertPublicKey(userID, key, name string, tx *sql.Tx) error { | |
| 399 | - | pk, _ := me.FindPublicKeyForKey(key) | |
| 352 | + | pk, _ := me.findPublicKeyForKey(key) | |
| 400 | 353 | if pk != nil { | |
| 401 | 354 | return db.ErrPublicKeyTaken | |
| 402 | 355 | } |
| ... | ... | @@ -415,7 +368,7 @@ func (me *PsqlDB) InsertPublicKey(userID, key, name string, tx *sql.Tx) error { | |
| 415 | 368 | } | |
| 416 | 369 | ||
| 417 | 370 | func (me *PsqlDB) UpdatePublicKey(pubkeyID, name string) (*db.PublicKey, error) { | |
| 418 | - | pk, err := me.FindPublicKey(pubkeyID) | |
| 371 | + | pk, err := me.findPublicKey(pubkeyID) | |
| 419 | 372 | if err != nil { | |
| 420 | 373 | return nil, err | |
| 421 | 374 | } |
| ... | ... | @@ -426,14 +379,14 @@ func (me *PsqlDB) UpdatePublicKey(pubkeyID, name string) (*db.PublicKey, error) | |
| 426 | 379 | return nil, err | |
| 427 | 380 | } | |
| 428 | 381 | ||
| 429 | - | pk, err = me.FindPublicKey(pubkeyID) | |
| 382 | + | pk, err = me.findPublicKey(pubkeyID) | |
| 430 | 383 | if err != nil { | |
| 431 | 384 | return nil, err | |
| 432 | 385 | } | |
| 433 | 386 | return pk, nil | |
| 434 | 387 | } | |
| 435 | 388 | ||
| 436 | - | func (me *PsqlDB) FindPublicKeyForKey(key string) (*db.PublicKey, error) { | |
| 389 | + | func (me *PsqlDB) findPublicKeyForKey(key string) (*db.PublicKey, error) { | |
| 437 | 390 | var keys []*db.PublicKey | |
| 438 | 391 | rs, err := me.Db.Query(sqlSelectPublicKey, key) | |
| 439 | 392 | if err != nil { |
| ... | ... | @@ -469,7 +422,7 @@ func (me *PsqlDB) FindPublicKeyForKey(key string) (*db.PublicKey, error) { | |
| 469 | 422 | return keys[0], nil | |
| 470 | 423 | } | |
| 471 | 424 | ||
| 472 | - | func (me *PsqlDB) FindPublicKey(pubkeyID string) (*db.PublicKey, error) { | |
| 425 | + | func (me *PsqlDB) findPublicKey(pubkeyID string) (*db.PublicKey, error) { | |
| 473 | 426 | var keys []*db.PublicKey | |
| 474 | 427 | rs, err := me.Db.Query(`SELECT id, user_id, name, public_key, created_at FROM public_keys WHERE id = $1`, pubkeyID) | |
| 475 | 428 | if err != nil { |
| ... | ... | @@ -524,28 +477,6 @@ func (me *PsqlDB) RemoveKeys(keyIDs []string) error { | |
| 524 | 477 | return err | |
| 525 | 478 | } | |
| 526 | 479 | ||
| 527 | - | func (me *PsqlDB) FindPostsBeforeDate(date *time.Time, space string) ([]*db.Post, error) { | |
| 528 | - | // now := time.Now() | |
| 529 | - | // expired := now.AddDate(0, 0, -3) | |
| 530 | - | var posts []*db.Post | |
| 531 | - | rs, err := me.Db.Query(sqlSelectPostsBeforeDate, date, space) | |
| 532 | - | if err != nil { | |
| 533 | - | return posts, err | |
| 534 | - | } | |
| 535 | - | for rs.Next() { | |
| 536 | - | post, err := CreatePostFromRow(rs) | |
| 537 | - | if err != nil { | |
| 538 | - | return nil, err | |
| 539 | - | } | |
| 540 | - | ||
| 541 | - | posts = append(posts, post) | |
| 542 | - | } | |
| 543 | - | if rs.Err() != nil { | |
| 544 | - | return posts, rs.Err() | |
| 545 | - | } | |
| 546 | - | return posts, nil | |
| 547 | - | } | |
| 548 | - | ||
| 549 | 480 | func (me *PsqlDB) FindUsersWithPost(space string) ([]*db.User, error) { | |
| 550 | 481 | var users []*db.User | |
| 551 | 482 | rs, err := me.Db.Query( |
| ... | ... | @@ -582,7 +513,7 @@ func (me *PsqlDB) FindUsersWithPost(space string) ([]*db.User, error) { | |
| 582 | 513 | ||
| 583 | 514 | func (me *PsqlDB) FindUserForKey(username string, key string) (*db.User, error) { | |
| 584 | 515 | me.Logger.Info("attempting to find user with only public key", "key", key) | |
| 585 | - | pk, err := me.FindPublicKeyForKey(key) | |
| 516 | + | pk, err := me.findPublicKeyForKey(key) | |
| 586 | 517 | if err == nil { | |
| 587 | 518 | me.Logger.Info("found pubkey, looking for user", "key", key, "userId", pk.UserID) | |
| 588 | 519 | user, err := me.FindUser(pk.UserID) |
| ... | ... | @@ -595,7 +526,7 @@ func (me *PsqlDB) FindUserForKey(username string, key string) (*db.User, error) | |
| 595 | 526 | ||
| 596 | 527 | if errors.Is(err, &db.ErrMultiplePublicKeys{}) { | |
| 597 | 528 | me.Logger.Info("detected multiple users with same public key", "user", username) | |
| 598 | - | user, err := me.FindUserForNameAndKey(username, key) | |
| 529 | + | user, err := me.findUserForNameAndKey(username, key) | |
| 599 | 530 | if err != nil { | |
| 600 | 531 | me.Logger.Info("could not find user by username and public key", "user", username, "key", key) | |
| 601 | 532 | // this is a little hacky but if we cannot find a user by name and public key |
| ... | ... | @@ -611,7 +542,7 @@ func (me *PsqlDB) FindUserForKey(username string, key string) (*db.User, error) | |
| 611 | 542 | ||
| 612 | 543 | func (me *PsqlDB) FindUserByPubkey(key string) (*db.User, error) { | |
| 613 | 544 | me.Logger.Info("attempting to find user with only public key", "key", key) | |
| 614 | - | pk, err := me.FindPublicKeyForKey(key) | |
| 545 | + | pk, err := me.findPublicKeyForKey(key) | |
| 615 | 546 | if err != nil { | |
| 616 | 547 | return nil, err | |
| 617 | 548 | } |
| ... | ... | @@ -639,7 +570,7 @@ func (me *PsqlDB) FindUser(userID string) (*db.User, error) { | |
| 639 | 570 | return user, nil | |
| 640 | 571 | } | |
| 641 | 572 | ||
| 642 | - | func (me *PsqlDB) ValidateName(name string) (bool, error) { | |
| 573 | + | func (me *PsqlDB) validateName(name string) (bool, error) { | |
| 643 | 574 | lower := strings.ToLower(name) | |
| 644 | 575 | if slices.Contains(db.DenyList, lower) { | |
| 645 | 576 | return false, fmt.Errorf("%s is on deny list: %w", lower, db.ErrNameDenied) |
| ... | ... | @@ -665,7 +596,7 @@ func (me *PsqlDB) FindUserByName(name string) (*db.User, error) { | |
| 665 | 596 | return user, nil | |
| 666 | 597 | } | |
| 667 | 598 | ||
| 668 | - | func (me *PsqlDB) FindUserForNameAndKey(name string, key string) (*db.User, error) { | |
| 599 | + | func (me *PsqlDB) findUserForNameAndKey(name string, key string) (*db.User, error) { | |
| 669 | 600 | user := &db.User{} | |
| 670 | 601 | pk := &db.PublicKey{} | |
| 671 | 602 |
| ... | ... | @@ -691,17 +622,6 @@ func (me *PsqlDB) FindUserForToken(token string) (*db.User, error) { | |
| 691 | 622 | return user, nil | |
| 692 | 623 | } | |
| 693 | 624 | ||
| 694 | - | func (me *PsqlDB) SetUserName(userID string, name string) error { | |
| 695 | - | lowerName := strings.ToLower(name) | |
| 696 | - | valid, err := me.ValidateName(lowerName) | |
| 697 | - | if !valid { | |
| 698 | - | return err | |
| 699 | - | } | |
| 700 | - | ||
| 701 | - | _, err = me.Db.Exec(sqlUpdateUserName, lowerName, userID) | |
| 702 | - | return err | |
| 703 | - | } | |
| 704 | - | ||
| 705 | 625 | func (me *PsqlDB) FindPostWithFilename(filename string, persona_id string, space string) (*db.Post, error) { | |
| 706 | 626 | r := me.Db.QueryRow(sqlSelectPostWithFilename, filename, persona_id, space) | |
| 707 | 627 | post, err := CreatePostWithTagsFromRow(r) |
| ... | ... | @@ -794,14 +714,6 @@ func (me *PsqlDB) FindPostsForFeed(page *db.Pager, space string) (*db.Paginate[* | |
| 794 | 714 | return me.postPager(rs, page.Num, space, "") | |
| 795 | 715 | } | |
| 796 | 716 | ||
| 797 | - | func (me *PsqlDB) FindAllUpdatedPosts(page *db.Pager, space string) (*db.Paginate[*db.Post], error) { | |
| 798 | - | rs, err := me.Db.Query(sqlSelectAllUpdatedPosts, page.Num, page.Num*page.Page, space) | |
| 799 | - | if err != nil { | |
| 800 | - | return nil, err | |
| 801 | - | } | |
| 802 | - | return me.postPager(rs, page.Num, space, "") | |
| 803 | - | } | |
| 804 | - | ||
| 805 | 717 | func (me *PsqlDB) InsertPost(post *db.Post) (*db.Post, error) { | |
| 806 | 718 | var id string | |
| 807 | 719 | err := me.Db.QueryRow( |
| ... | ... | @@ -956,26 +868,6 @@ func (me *PsqlDB) FindExpiredPosts(space string) ([]*db.Post, error) { | |
| 956 | 868 | return posts, nil | |
| 957 | 869 | } | |
| 958 | 870 | ||
| 959 | - | func (me *PsqlDB) FindUpdatedPostsForUser(userID string, space string) ([]*db.Post, error) { | |
| 960 | - | var posts []*db.Post | |
| 961 | - | rs, err := me.Db.Query(sqlSelectUpdatedPostsForUser, userID, space) | |
| 962 | - | if err != nil { | |
| 963 | - | return posts, err | |
| 964 | - | } | |
| 965 | - | for rs.Next() { | |
| 966 | - | post, err := CreatePostFromRow(rs) | |
| 967 | - | if err != nil { | |
| 968 | - | return nil, err | |
| 969 | - | } | |
| 970 | - | ||
| 971 | - | posts = append(posts, post) | |
| 972 | - | } | |
| 973 | - | if rs.Err() != nil { | |
| 974 | - | return posts, rs.Err() | |
| 975 | - | } | |
| 976 | - | return posts, nil | |
| 977 | - | } | |
| 978 | - | ||
| 979 | 871 | func (me *PsqlDB) Close() error { | |
| 980 | 872 | me.Logger.Info("Closing db") | |
| 981 | 873 | return me.Db.Close() |
| ... | ... | @@ -1447,51 +1339,6 @@ func (me *PsqlDB) FindPopularTags(space string) ([]string, error) { | |
| 1447 | 1339 | return tags, nil | |
| 1448 | 1340 | } | |
| 1449 | 1341 | ||
| 1450 | - | func (me *PsqlDB) FindTagsForUser(userID string, space string) ([]string, error) { | |
| 1451 | - | tags := []string{} | |
| 1452 | - | rs, err := me.Db.Query(sqlSelectTagsForUser, userID, space) | |
| 1453 | - | if err != nil { | |
| 1454 | - | return tags, err | |
| 1455 | - | } | |
| 1456 | - | for rs.Next() { | |
| 1457 | - | name := "" | |
| 1458 | - | err := rs.Scan(&name) | |
| 1459 | - | if err != nil { | |
| 1460 | - | return tags, err | |
| 1461 | - | } | |
| 1462 | - | ||
| 1463 | - | tags = append(tags, name) | |
| 1464 | - | } | |
| 1465 | - | if rs.Err() != nil { | |
| 1466 | - | return tags, rs.Err() | |
| 1467 | - | } | |
| 1468 | - | return tags, nil | |
| 1469 | - | } | |
| 1470 | - | ||
| 1471 | - | func (me *PsqlDB) FindTagsForPost(postID string) ([]string, error) { | |
| 1472 | - | tags := make([]string, 0) | |
| 1473 | - | rs, err := me.Db.Query(sqlSelectTagsForPost, postID) | |
| 1474 | - | if err != nil { | |
| 1475 | - | return tags, err | |
| 1476 | - | } | |
| 1477 | - | ||
| 1478 | - | for rs.Next() { | |
| 1479 | - | name := "" | |
| 1480 | - | err := rs.Scan(&name) | |
| 1481 | - | if err != nil { | |
| 1482 | - | return tags, err | |
| 1483 | - | } | |
| 1484 | - | ||
| 1485 | - | tags = append(tags, name) | |
| 1486 | - | } | |
| 1487 | - | ||
| 1488 | - | if rs.Err() != nil { | |
| 1489 | - | return tags, rs.Err() | |
| 1490 | - | } | |
| 1491 | - | ||
| 1492 | - | return tags, nil | |
| 1493 | - | } | |
| 1494 | - | ||
| 1495 | 1342 | func (me *PsqlDB) FindFeature(userID string, feature string) (*db.FeatureFlag, error) { | |
| 1496 | 1343 | ff := &db.FeatureFlag{} | |
| 1497 | 1344 | // payment history is allowed to be null |
| ... | ... | @@ -1560,15 +1407,6 @@ func (me *PsqlDB) HasFeatureForUser(userID string, feature string) bool { | |
| 1560 | 1407 | return ff.IsValid() | |
| 1561 | 1408 | } | |
| 1562 | 1409 | ||
| 1563 | - | func (me *PsqlDB) FindTotalSizeForUser(userID string) (int, error) { | |
| 1564 | - | var fileSize int | |
| 1565 | - | err := me.Db.QueryRow(sqlSelectSizeForUser, userID).Scan(&fileSize) | |
| 1566 | - | if err != nil { | |
| 1567 | - | return 0, err | |
| 1568 | - | } | |
| 1569 | - | return fileSize, nil | |
| 1570 | - | } | |
| 1571 | - | ||
| 1572 | 1410 | func (me *PsqlDB) InsertFeedItems(postID string, items []*db.FeedItem) error { | |
| 1573 | 1411 | ctx := context.Background() | |
| 1574 | 1412 | tx, err := me.Db.BeginTx(ctx, nil) |
| ... | ... | @@ -1677,7 +1515,7 @@ func (me *PsqlDB) InsertToken(userID, name string) (string, error) { | |
| 1677 | 1515 | } | |
| 1678 | 1516 | ||
| 1679 | 1517 | func (me *PsqlDB) UpsertToken(userID, name string) (string, error) { | |
| 1680 | - | token, _ := me.FindTokenByName(userID, name) | |
| 1518 | + | token, _ := me.findTokenByName(userID, name) | |
| 1681 | 1519 | if token != "" { | |
| 1682 | 1520 | return token, nil | |
| 1683 | 1521 | } |
| ... | ... | @@ -1686,7 +1524,7 @@ func (me *PsqlDB) UpsertToken(userID, name string) (string, error) { | |
| 1686 | 1524 | return token, err | |
| 1687 | 1525 | } | |
| 1688 | 1526 | ||
| 1689 | - | func (me *PsqlDB) FindTokenByName(userID, name string) (string, error) { | |
| 1527 | + | func (me *PsqlDB) findTokenByName(userID, name string) (string, error) { | |
| 1690 | 1528 | var token string | |
| 1691 | 1529 | err := me.Db.QueryRow(sqlSelectTokenByNameForUser, userID, name).Scan(&token) | |
| 1692 | 1530 | if err != nil { |
+2
-62
pkg/db/stub/stub.go
#
| ... | ... | @@ -29,24 +29,12 @@ func (me *StubDB) RegisterUser(username, pubkey, comment string) (*db.User, erro | |
| 29 | 29 | return nil, errNotImpl | |
| 30 | 30 | } | |
| 31 | 31 | ||
| 32 | - | func (me *StubDB) RemoveUsers(userIDs []string) error { | |
| 33 | - | return errNotImpl | |
| 34 | - | } | |
| 35 | - | ||
| 36 | - | func (me *StubDB) InsertPublicKey(userID, key, name string, tx *sql.Tx) error { | |
| 37 | - | return errNotImpl | |
| 38 | - | } | |
| 39 | - | ||
| 40 | 32 | func (me *StubDB) UpdatePublicKey(pubkeyID, name string) (*db.PublicKey, error) { | |
| 41 | 33 | return nil, errNotImpl | |
| 42 | 34 | } | |
| 43 | 35 | ||
| 44 | - | func (me *StubDB) FindPublicKeyForKey(key string) (*db.PublicKey, error) { | |
| 45 | - | return nil, errNotImpl | |
| 46 | - | } | |
| 47 | - | ||
| 48 | - | func (me *StubDB) FindPublicKey(pubkeyID string) (*db.PublicKey, error) { | |
| 49 | - | return nil, errNotImpl | |
| 36 | + | func (me *StubDB) InsertPublicKey(userID, key, name string, tx *sql.Tx) error { | |
| 37 | + | return errNotImpl | |
| 50 | 38 | } | |
| 51 | 39 | ||
| 52 | 40 | func (me *StubDB) FindKeysForUser(user *db.User) ([]*db.PublicKey, error) { |
| ... | ... | @@ -57,10 +45,6 @@ func (me *StubDB) RemoveKeys(keyIDs []string) error { | |
| 57 | 45 | return errNotImpl | |
| 58 | 46 | } | |
| 59 | 47 | ||
| 60 | - | func (me *StubDB) FindPostsBeforeDate(date *time.Time, space string) ([]*db.Post, error) { | |
| 61 | - | return []*db.Post{}, errNotImpl | |
| 62 | - | } | |
| 63 | - | ||
| 64 | 48 | func (me *StubDB) FindUserForKey(username string, key string) (*db.User, error) { | |
| 65 | 49 | return nil, errNotImpl | |
| 66 | 50 | } |
| ... | ... | @@ -73,26 +57,14 @@ func (me *StubDB) FindUser(userID string) (*db.User, error) { | |
| 73 | 57 | return nil, errNotImpl | |
| 74 | 58 | } | |
| 75 | 59 | ||
| 76 | - | func (me *StubDB) ValidateName(name string) (bool, error) { | |
| 77 | - | return false, errNotImpl | |
| 78 | - | } | |
| 79 | - | ||
| 80 | 60 | func (me *StubDB) FindUserByName(name string) (*db.User, error) { | |
| 81 | 61 | return nil, errNotImpl | |
| 82 | 62 | } | |
| 83 | 63 | ||
| 84 | - | func (me *StubDB) FindUserForNameAndKey(name string, key string) (*db.User, error) { | |
| 85 | - | return nil, errNotImpl | |
| 86 | - | } | |
| 87 | - | ||
| 88 | 64 | func (me *StubDB) FindUserForToken(token string) (*db.User, error) { | |
| 89 | 65 | return nil, errNotImpl | |
| 90 | 66 | } | |
| 91 | 67 | ||
| 92 | - | func (me *StubDB) SetUserName(userID string, name string) error { | |
| 93 | - | return errNotImpl | |
| 94 | - | } | |
| 95 | - | ||
| 96 | 68 | func (me *StubDB) FindPostWithFilename(filename string, persona_id string, space string) (*db.Post, error) { | |
| 97 | 69 | return nil, errNotImpl | |
| 98 | 70 | } |
| ... | ... | @@ -109,10 +81,6 @@ func (me *StubDB) FindPostsForFeed(page *db.Pager, space string) (*db.Paginate[* | |
| 109 | 81 | return &db.Paginate[*db.Post]{}, errNotImpl | |
| 110 | 82 | } | |
| 111 | 83 | ||
| 112 | - | func (me *StubDB) FindAllUpdatedPosts(page *db.Pager, space string) (*db.Paginate[*db.Post], error) { | |
| 113 | - | return &db.Paginate[*db.Post]{}, errNotImpl | |
| 114 | - | } | |
| 115 | - | ||
| 116 | 84 | func (me *StubDB) InsertPost(post *db.Post) (*db.Post, error) { | |
| 117 | 85 | return nil, errNotImpl | |
| 118 | 86 | } |
| ... | ... | @@ -141,10 +109,6 @@ func (me *StubDB) FindExpiredPosts(space string) ([]*db.Post, error) { | |
| 141 | 109 | return []*db.Post{}, errNotImpl | |
| 142 | 110 | } | |
| 143 | 111 | ||
| 144 | - | func (me *StubDB) FindUpdatedPostsForUser(userID string, space string) ([]*db.Post, error) { | |
| 145 | - | return []*db.Post{}, errNotImpl | |
| 146 | - | } | |
| 147 | - | ||
| 148 | 112 | func (me *StubDB) Close() error { | |
| 149 | 113 | return errNotImpl | |
| 150 | 114 | } |
| ... | ... | @@ -185,10 +149,6 @@ func (me *StubDB) FindPopularTags(space string) ([]string, error) { | |
| 185 | 149 | return []string{}, errNotImpl | |
| 186 | 150 | } | |
| 187 | 151 | ||
| 188 | - | func (me *StubDB) FindTagsForPost(postID string) ([]string, error) { | |
| 189 | - | return []string{}, errNotImpl | |
| 190 | - | } | |
| 191 | - | ||
| 192 | 152 | func (me *StubDB) FindFeature(userID string, feature string) (*db.FeatureFlag, error) { | |
| 193 | 153 | return nil, errNotImpl | |
| 194 | 154 | } |
| ... | ... | @@ -201,10 +161,6 @@ func (me *StubDB) HasFeatureForUser(userID string, feature string) bool { | |
| 201 | 161 | return false | |
| 202 | 162 | } | |
| 203 | 163 | ||
| 204 | - | func (me *StubDB) FindTotalSizeForUser(userID string) (int, error) { | |
| 205 | - | return 0, errNotImpl | |
| 206 | - | } | |
| 207 | - | ||
| 208 | 164 | func (me *StubDB) InsertFeedItems(postID string, items []*db.FeedItem) error { | |
| 209 | 165 | return errNotImpl | |
| 210 | 166 | } |
| ... | ... | @@ -217,14 +173,6 @@ func (me *StubDB) UpsertProject(userID, name, projectDir string) (*db.Project, e | |
| 217 | 173 | return nil, errNotImpl | |
| 218 | 174 | } | |
| 219 | 175 | ||
| 220 | - | func (me *StubDB) InsertProject(userID, name, projectDir string) (string, error) { | |
| 221 | - | return "", errNotImpl | |
| 222 | - | } | |
| 223 | - | ||
| 224 | - | func (me *StubDB) UpdateProject(userID, name string) error { | |
| 225 | - | return errNotImpl | |
| 226 | - | } | |
| 227 | - | ||
| 228 | 176 | func (me *StubDB) FindProjectByName(userID, name string) (*db.Project, error) { | |
| 229 | 177 | return &db.Project{}, errNotImpl | |
| 230 | 178 | } |
| ... | ... | @@ -237,10 +185,6 @@ func (me *StubDB) UpsertToken(userID, name string) (string, error) { | |
| 237 | 185 | return "", errNotImpl | |
| 238 | 186 | } | |
| 239 | 187 | ||
| 240 | - | func (me *StubDB) FindTokenByName(userID, name string) (string, error) { | |
| 241 | - | return "", errNotImpl | |
| 242 | - | } | |
| 243 | - | ||
| 244 | 188 | func (me *StubDB) RemoveToken(tokenID string) error { | |
| 245 | 189 | return errNotImpl | |
| 246 | 190 | } |
| ... | ... | @@ -261,10 +205,6 @@ func (me *StubDB) AddPicoPlusUser(username, email, paymentType, txId string) err | |
| 261 | 205 | return errNotImpl | |
| 262 | 206 | } | |
| 263 | 207 | ||
| 264 | - | func (me *StubDB) FindTagsForUser(userID string, tag string) ([]string, error) { | |
| 265 | - | return []string{}, errNotImpl | |
| 266 | - | } | |
| 267 | - | ||
| 268 | 208 | func (me *StubDB) FindUserStats(userID string) (*db.UserStats, error) { | |
| 269 | 209 | return nil, errNotImpl | |
| 270 | 210 | } |