This commit is contained in:
Simon Ser 2022-01-10 15:34:48 +00:00 committed by Drew DeVault
parent e369a0723e
commit 8000340edf
5 changed files with 23 additions and 23 deletions

View File

@ -33,11 +33,11 @@ func (file *File) Fields() *database.ModelFields {
}
file.fields = &database.ModelFields{
Fields: []*database.FieldMap{
{ "filename", "filename", &file.Filename },
{"filename", "filename", &file.Filename},
// Always fetch:
{ "paste_id", "", &file.PasteID },
{ "blob_id", "", &file.BlobID },
{"paste_id", "", &file.PasteID},
{"blob_id", "", &file.BlobID},
},
}
return file.fields

View File

@ -53,13 +53,13 @@ func (paste *Paste) Fields() *database.ModelFields {
}
paste.fields = &database.ModelFields{
Fields: []*database.FieldMap{
{ "created", "created", &paste.Created },
{ "visibility", "visibility", &paste.RawVisibility },
{"created", "created", &paste.Created},
{"visibility", "visibility", &paste.RawVisibility},
// Always fetch:
{ "id", "", &paste.PKID },
{ "sha", "", &paste.ID },
{ "user_id", "", &paste.UserID },
{"id", "", &paste.PKID},
{"sha", "", &paste.ID},
{"user_id", "", &paste.UserID},
},
}
return paste.fields
@ -75,7 +75,7 @@ func (paste *Paste) QueryWithCursor(ctx context.Context,
if cur.Next != "" {
next, _ := strconv.Atoi(cur.Next)
q = q.Where(database.WithAlias(paste.alias, "id") + "<= ?", next)
q = q.Where(database.WithAlias(paste.alias, "id")+"<= ?", next)
}
q = q.
Column(database.WithAlias(paste.alias, "id")).
@ -94,8 +94,8 @@ func (paste *Paste) QueryWithCursor(ctx context.Context,
for rows.Next() {
var paste Paste
if err := rows.Scan(append(
database.Scan(ctx, &paste),
&id)...); err != nil {
database.Scan(ctx, &paste),
&id)...); err != nil {
panic(err)
}
pastes = append(pastes, &paste)

View File

@ -40,11 +40,11 @@ func (u *User) Fields() *database.ModelFields {
}
u.fields = &database.ModelFields{
Fields: []*database.FieldMap{
{ "created", "created", &u.Created },
{"created", "created", &u.Created},
// Always fetch:
{ "id", "", &u.ID },
{ "username", "", &u.Username },
{"id", "", &u.ID},
{"username", "", &u.Username},
},
}
return u.fields

View File

@ -38,8 +38,8 @@ func fetchBlobsByID(ctx context.Context) func(ids []int) ([]*model.Blob, []error
blobs := make([]*model.Blob, len(ids))
if err := database.WithTx(ctx, &sql.TxOptions{
Isolation: 0,
ReadOnly: true,
}, func (tx *sql.Tx) error {
ReadOnly: true,
}, func(tx *sql.Tx) error {
rows, err := tx.QueryContext(ctx, `
SELECT id, sha FROM blob WHERE id = ANY($1);
`, pq.Array(ids))
@ -76,8 +76,8 @@ func fetchPastesBySHA(ctx context.Context) func(shas []string) ([]*model.Paste,
pastes := make([]*model.Paste, len(shas))
if err := database.WithTx(ctx, &sql.TxOptions{
Isolation: 0,
ReadOnly: true,
}, func (tx *sql.Tx) error {
ReadOnly: true,
}, func(tx *sql.Tx) error {
var (
err error
rows *sql.Rows
@ -126,8 +126,8 @@ func fetchUsersByID(ctx context.Context) func(ids []int) ([]*model.User, []error
users := make([]*model.User, len(ids))
if err := database.WithTx(ctx, &sql.TxOptions{
Isolation: 0,
ReadOnly: true,
}, func (tx *sql.Tx) error {
ReadOnly: true,
}, func(tx *sql.Tx) error {
var (
err error
rows *sql.Rows
@ -169,8 +169,8 @@ func fetchUsersByName(ctx context.Context) func(names []string) ([]*model.User,
users := make([]*model.User, len(names))
if err := database.WithTx(ctx, &sql.TxOptions{
Isolation: 0,
ReadOnly: true,
}, func (tx *sql.Tx) error {
ReadOnly: true,
}, func(tx *sql.Tx) error {
var (
err error
rows *sql.Rows

View File

@ -2,8 +2,8 @@ package main
import (
"context"
"net/http"
"database/sql"
"net/http"
"git.sr.ht/~sircmpwn/core-go/config"
"git.sr.ht/~sircmpwn/core-go/database"