rename postgr fucntions
This commit is contained in:
@@ -19,7 +19,7 @@ func withCORS(h http.HandlerFunc) http.HandlerFunc {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
postgresql.PgInit(ctx)
|
postgresql.Init(ctx)
|
||||||
|
|
||||||
http.HandleFunc("/new/user", withCORS(http2.HandleUserNew))
|
http.HandleFunc("/new/user", withCORS(http2.HandleUserNew))
|
||||||
http.HandleFunc("/new/connection", withCORS(http2.HandleUserNewConnection))
|
http.HandleFunc("/new/connection", withCORS(http2.HandleUserNewConnection))
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ func HandleDm(response http.ResponseWriter, request *http.Request) {
|
|||||||
Event: message,
|
Event: message,
|
||||||
})
|
})
|
||||||
|
|
||||||
err = postgresql.PgConnectionMessageSave(ctx, message)
|
err = postgresql.ConnectionMessageSave(ctx, message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@@ -139,7 +139,7 @@ func HandleUserGetConnectionMessages(response http.ResponseWriter, request *http
|
|||||||
if validBufCount > 0 {
|
if validBufCount > 0 {
|
||||||
cutoff = buffer[0].CreatedAt
|
cutoff = buffer[0].CreatedAt
|
||||||
}
|
}
|
||||||
dbMessages, err := postgresql.PgConnectionGetMessagesBefore(ctx, cutoff, connectionId, remaining)
|
dbMessages, err := postgresql.ConnectionGetMessagesBefore(ctx, cutoff, connectionId, remaining)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@@ -204,7 +204,7 @@ func HandleUserNewConnection(response http.ResponseWriter, request *http.Request
|
|||||||
RecipientId: recipient.Id,
|
RecipientId: recipient.Id,
|
||||||
State: ConnectionState.Stranger,
|
State: ConnectionState.Stranger,
|
||||||
}
|
}
|
||||||
err = postgresql.PgConnectionSave(ctx, connection)
|
err = postgresql.ConnectionSave(ctx, connection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@@ -264,7 +264,7 @@ func HandleUserDeleteConnection(response http.ResponseWriter, request *http.Requ
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = postgresql.PgConnectionDelete(ctx, conn)
|
err = postgresql.ConnectionDelete(ctx, conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@@ -315,7 +315,7 @@ func HandleUserElevateConnection(response http.ResponseWriter, request *http.Req
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = postgresql.PgConnectionUpdateState(ctx, conn)
|
err = postgresql.ConnectionUpdateState(ctx, conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|||||||
+11
-2
@@ -5,12 +5,15 @@ import (
|
|||||||
"go-socket/packages/convertions"
|
"go-socket/packages/convertions"
|
||||||
"go-socket/packages/globals"
|
"go-socket/packages/globals"
|
||||||
"go-socket/packages/minio"
|
"go-socket/packages/minio"
|
||||||
|
"go-socket/packages/postgresql"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func handleExistingUpload() {
|
func handleExistingUpload() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleFileUpload(response http.ResponseWriter, request *http.Request) {
|
func HandleFileUpload(response http.ResponseWriter, request *http.Request) {
|
||||||
@@ -71,11 +74,17 @@ func HandleFileUpload(response http.ResponseWriter, request *http.Request) {
|
|||||||
if minio.DoesExist(ctx, key) {
|
if minio.DoesExist(ctx, key) {
|
||||||
part.Close()
|
part.Close()
|
||||||
uploaded = true
|
uploaded = true
|
||||||
|
handleExistingUpload()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err = minio.Upload(ctx, key, part, -1, contentType, user.Id)
|
id := uuid.New()
|
||||||
|
err = minio.Upload(ctx, key, part, -1, contentType, id)
|
||||||
|
|
||||||
|
postgresql.FileMetadataSave()
|
||||||
|
|
||||||
part.Close()
|
part.Close()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(response, "upload failed", http.StatusInternalServerError)
|
http.Error(response, "upload failed", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ func getUserById(ctx context.Context, userId uuid.UUID) (*types.User, error) {
|
|||||||
user, err := cache.CacheGetUserById(userId)
|
user, err := cache.CacheGetUserById(userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
user = &types.User{Id: userId}
|
user = &types.User{Id: userId}
|
||||||
err = postgresql.PgGetWholeUser(ctx, user)
|
err = postgresql.GetWholeUser(ctx, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,11 +42,11 @@ func HandleUserNewToken(response http.ResponseWriter, request *http.Request) {
|
|||||||
user, err = cache.CacheGetUserByName(username)
|
user, err = cache.CacheGetUserByName(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
user = &types.User{Name: username}
|
user = &types.User{Name: username}
|
||||||
if err = postgresql.PgUserGetStandardInfoByName(ctx, user); err != nil {
|
if err = postgresql.UserGetStandardInfoByName(ctx, user); err != nil {
|
||||||
http.Error(response, "bad login", http.StatusUnauthorized)
|
http.Error(response, "bad login", http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = postgresql.PgGetWholeUser(ctx, user); err != nil {
|
if err = postgresql.GetWholeUser(ctx, user); err != nil {
|
||||||
http.Error(response, err.Error(), http.StatusInternalServerError)
|
http.Error(response, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -106,7 +106,7 @@ func HandleUserNew(response http.ResponseWriter, request *http.Request) {
|
|||||||
|
|
||||||
ctx := request.Context()
|
ctx := request.Context()
|
||||||
|
|
||||||
err = postgresql.PgUserSave(ctx, newUser)
|
err = postgresql.UserSave(ctx, newUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(response, "name taken", http.StatusUnauthorized)
|
http.Error(response, "name taken", http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
@@ -127,7 +127,7 @@ func HandleUserDelete(response http.ResponseWriter, request *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = postgresql.PgUserDelete(ctx, userId)
|
err = postgresql.UserDelete(ctx, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@@ -156,7 +156,7 @@ func HandleUserModifyAppearance(response http.ResponseWriter, request *http.Requ
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
user.Color = color
|
user.Color = color
|
||||||
err = postgresql.PgUserSetColor(ctx, user)
|
err = postgresql.UserSetColor(ctx, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@@ -184,7 +184,7 @@ func HandleUserModifyAbout(response http.ResponseWriter, request *http.Request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
user.Pronouns = pronouns
|
user.Pronouns = pronouns
|
||||||
err = postgresql.PgUserSetPronouns(ctx, user)
|
err = postgresql.UserSetPronouns(ctx, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ func GetKey(hash string, contentType string) string {
|
|||||||
return hash + extensionFromContentType(contentType)
|
return hash + extensionFromContentType(contentType)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MinInit() {
|
func Init() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
@@ -65,14 +65,14 @@ func MinInit() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Upload(ctx context.Context, key string, body io.Reader, size int64, contentType string, uploader uuid.UUID) error {
|
func Upload(ctx context.Context, key string, body io.Reader, size int64, contentType string, id uuid.UUID) error {
|
||||||
_, err := minClient.PutObject(ctx, globals.FileStorageBucketName, key, body, size,
|
_, err := minClient.PutObject(ctx, globals.FileStorageBucketName, key, body, size,
|
||||||
minio.PutObjectOptions{
|
minio.PutObjectOptions{
|
||||||
ContentType: contentType,
|
ContentType: contentType,
|
||||||
PartSize: globals.FileProcessingPartSize,
|
PartSize: globals.FileProcessingPartSize,
|
||||||
NumThreads: globals.FileProcessingThreads,
|
NumThreads: globals.FileProcessingThreads,
|
||||||
UserMetadata: map[string]string{
|
UserMetadata: map[string]string{
|
||||||
"uploader": uploader.String(),
|
"id": id.String(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import (
|
|||||||
|
|
||||||
var dbConn *pgxpool.Pool
|
var dbConn *pgxpool.Pool
|
||||||
|
|
||||||
func PgInit(ctx context.Context) {
|
func Init(ctx context.Context) {
|
||||||
var err error
|
var err error
|
||||||
dbConn, err = pgxpool.New(ctx, "postgres://master:secret@localhost:5432") // TODO change to env in production
|
dbConn, err = pgxpool.New(ctx, "postgres://master:secret@localhost:5432") // TODO change to env in production
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -91,7 +91,7 @@ func PgInit(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgUserSave(ctx context.Context, user *types.User) error {
|
func UserSave(ctx context.Context, user *types.User) error {
|
||||||
err := dbConn.QueryRow(ctx, `
|
err := dbConn.QueryRow(ctx, `
|
||||||
INSERT INTO users (name, pass_hash, pronouns, rgba, created_at)
|
INSERT INTO users (name, pass_hash, pronouns, rgba, created_at)
|
||||||
VALUES ($1, $2, $3, $4, $5)
|
VALUES ($1, $2, $3, $4, $5)
|
||||||
@@ -101,14 +101,14 @@ func PgUserSave(ctx context.Context, user *types.User) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgUserDelete(ctx context.Context, id uuid.UUID) error {
|
func UserDelete(ctx context.Context, id uuid.UUID) error {
|
||||||
_, err := dbConn.Exec(ctx, `
|
_, err := dbConn.Exec(ctx, `
|
||||||
DELETE FROM users WHERE id = $1
|
DELETE FROM users WHERE id = $1
|
||||||
`, id)
|
`, id)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgUserGetStandardInfoByName(ctx context.Context, user *types.User) error {
|
func UserGetStandardInfoByName(ctx context.Context, user *types.User) error {
|
||||||
var rgba int64
|
var rgba int64
|
||||||
err := dbConn.QueryRow(ctx, `
|
err := dbConn.QueryRow(ctx, `
|
||||||
SELECT id, name, pass_hash, COALESCE(pronouns, ''), rgba, created_at FROM users WHERE name = $1
|
SELECT id, name, pass_hash, COALESCE(pronouns, ''), rgba, created_at FROM users WHERE name = $1
|
||||||
@@ -119,7 +119,7 @@ func PgUserGetStandardInfoByName(ctx context.Context, user *types.User) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgUserGetById(ctx context.Context, user *types.User) error {
|
func UserGetById(ctx context.Context, user *types.User) error {
|
||||||
var rgba int64
|
var rgba int64
|
||||||
err := dbConn.QueryRow(ctx, `
|
err := dbConn.QueryRow(ctx, `
|
||||||
SELECT name, pass_hash, COALESCE(pronouns, ''), rgba, created_at FROM users WHERE id = $1
|
SELECT name, pass_hash, COALESCE(pronouns, ''), rgba, created_at FROM users WHERE id = $1
|
||||||
@@ -130,25 +130,25 @@ func PgUserGetById(ctx context.Context, user *types.User) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgUserSetColor(ctx context.Context, user *types.User) error {
|
func UserSetColor(ctx context.Context, user *types.User) error {
|
||||||
_, err := dbConn.Exec(ctx, `
|
_, err := dbConn.Exec(ctx, `
|
||||||
UPDATE users SET rgba = $1 WHERE id = $2
|
UPDATE users SET rgba = $1 WHERE id = $2
|
||||||
`, convertions.RgbaToUint32(user.Color), user.Id)
|
`, convertions.RgbaToUint32(user.Color), user.Id)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgUserSetPronouns(ctx context.Context, user *types.User) error {
|
func UserSetPronouns(ctx context.Context, user *types.User) error {
|
||||||
_, err := dbConn.Exec(ctx, `
|
_, err := dbConn.Exec(ctx, `
|
||||||
UPDATE users SET pronouns = $1 WHERE id = $2
|
UPDATE users SET pronouns = $1 WHERE id = $2
|
||||||
`, user.Pronouns, user.Id)
|
`, user.Pronouns, user.Id)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgGetWholeUser(ctx context.Context, user *types.User) error {
|
func GetWholeUser(ctx context.Context, user *types.User) error {
|
||||||
if err := PgUserGetById(ctx, user); err != nil {
|
if err := UserGetById(ctx, user); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := PgConnectionsGetBelongingToUser(ctx, user); err != nil {
|
if err := ConnectionsGetBelongingToUser(ctx, user); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,21 +156,21 @@ func PgGetWholeUser(ctx context.Context, user *types.User) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgConnectionSave(ctx context.Context, conn *types.Connection) error {
|
func ConnectionSave(ctx context.Context, conn *types.Connection) error {
|
||||||
return dbConn.QueryRow(ctx, `
|
return dbConn.QueryRow(ctx, `
|
||||||
INSERT INTO user_connections (requestor_id, recipient_id, state, created_at) VALUES ($1, $2, $3, $4)
|
INSERT INTO user_connections (requestor_id, recipient_id, state, created_at) VALUES ($1, $2, $3, $4)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`, conn.RequestorId, conn.RecipientId, conn.State, conn.CreatedAt).Scan(&conn.Id)
|
`, conn.RequestorId, conn.RecipientId, conn.State, conn.CreatedAt).Scan(&conn.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgConnectionDelete(ctx context.Context, conn *types.Connection) error {
|
func ConnectionDelete(ctx context.Context, conn *types.Connection) error {
|
||||||
_, err := dbConn.Exec(ctx, `
|
_, err := dbConn.Exec(ctx, `
|
||||||
DELETE FROM user_connections WHERE id = $1
|
DELETE FROM user_connections WHERE id = $1
|
||||||
`, conn.Id)
|
`, conn.Id)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgConnectionsGetBelongingToUser(ctx context.Context, user *types.User) error {
|
func ConnectionsGetBelongingToUser(ctx context.Context, user *types.User) error {
|
||||||
rows, err := dbConn.Query(ctx, `
|
rows, err := dbConn.Query(ctx, `
|
||||||
SELECT id, requestor_id, recipient_id, state, created_at
|
SELECT id, requestor_id, recipient_id, state, created_at
|
||||||
FROM user_connections
|
FROM user_connections
|
||||||
@@ -195,14 +195,14 @@ func PgConnectionsGetBelongingToUser(ctx context.Context, user *types.User) erro
|
|||||||
return rows.Err()
|
return rows.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgConnectionUpdateState(ctx context.Context, conn *types.Connection) error {
|
func ConnectionUpdateState(ctx context.Context, conn *types.Connection) error {
|
||||||
_, err := dbConn.Exec(ctx, `
|
_, err := dbConn.Exec(ctx, `
|
||||||
UPDATE user_connections SET state = $1 WHERE id = $2
|
UPDATE user_connections SET state = $1 WHERE id = $2
|
||||||
`, conn.State, conn.Id)
|
`, conn.State, conn.Id)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgConnectionMessageSave(ctx context.Context, message *types.Message) error {
|
func ConnectionMessageSave(ctx context.Context, message *types.Message) error {
|
||||||
if message.Id != (uuid.UUID{}) {
|
if message.Id != (uuid.UUID{}) {
|
||||||
_, err := dbConn.Exec(ctx, `
|
_, err := dbConn.Exec(ctx, `
|
||||||
INSERT INTO direct_messages (id, sender_id, receiver_id, created_at, content) VALUES ($1, $2, $3, $4, $5)
|
INSERT INTO direct_messages (id, sender_id, receiver_id, created_at, content) VALUES ($1, $2, $3, $4, $5)
|
||||||
@@ -215,7 +215,7 @@ func PgConnectionMessageSave(ctx context.Context, message *types.Message) error
|
|||||||
`, message.Sender, message.Receiver, message.CreatedAt, message.Content).Scan(&message.Id)
|
`, message.Sender, message.Receiver, message.CreatedAt, message.Content).Scan(&message.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgConnectionGetMessagesBefore(ctx context.Context, before time.Time, connection uuid.UUID, cap uint32) ([]*types.Message, error) {
|
func ConnectionGetMessagesBefore(ctx context.Context, before time.Time, connection uuid.UUID, cap uint32) ([]*types.Message, error) {
|
||||||
rows, err := dbConn.Query(ctx, `
|
rows, err := dbConn.Query(ctx, `
|
||||||
SELECT id, sender_id, receiver_id, created_at, content
|
SELECT id, sender_id, receiver_id, created_at, content
|
||||||
FROM (
|
FROM (
|
||||||
@@ -244,34 +244,34 @@ func PgConnectionGetMessagesBefore(ctx context.Context, before time.Time, connec
|
|||||||
return messages, rows.Err()
|
return messages, rows.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgFileMetadataSave(ctx context.Context, metadata *types.FileMetadata) error {
|
func FileMetadataSave(ctx context.Context, metadata *types.FileMetadata) error {
|
||||||
_, err := dbConn.Exec(ctx, `
|
_, err := dbConn.Exec(ctx, `
|
||||||
INSERT INTO files_metadata (id, uploader_id, name, hash, created_at) VALUES ($1, $2, $3, $4, $5)
|
INSERT INTO files_metadata (id, uploader_id, name, hash, created_at) VALUES ($1, $2, $3, $4, $5)
|
||||||
`, metadata.Id, metadata.UploaderId, metadata.Name, metadata.Hash, metadata.CreatedAt)
|
`, metadata.Id, metadata.UploaderId, metadata.Name, metadata.Hash, metadata.CreatedAt)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgFileMetadataGet(ctx context.Context, metadata *types.FileMetadata) error {
|
func FileMetadataGet(ctx context.Context, metadata *types.FileMetadata) error {
|
||||||
return dbConn.QueryRow(ctx, `
|
return dbConn.QueryRow(ctx, `
|
||||||
SELECT uploader_id, name, hash, created_at FROM files_metadata WHERE id = $1
|
SELECT uploader_id, name, hash, created_at FROM files_metadata WHERE id = $1
|
||||||
`, metadata.Id).Scan(&metadata.UploaderId, &metadata.Name, &metadata.Hash, &metadata.CreatedAt)
|
`, metadata.Id).Scan(&metadata.UploaderId, &metadata.Name, &metadata.Hash, &metadata.CreatedAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgFileMetadataDelete(ctx context.Context, metadataId *uuid.UUID) error {
|
func FileMetadataDelete(ctx context.Context, metadataId *uuid.UUID) error {
|
||||||
_, err := dbConn.Exec(ctx, `
|
_, err := dbConn.Exec(ctx, `
|
||||||
DELETE FROM files_metadata WHERE id = $1
|
DELETE FROM files_metadata WHERE id = $1
|
||||||
`, metadataId)
|
`, metadataId)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgFileConnectionsAdd(ctx context.Context, metadataId *uuid.UUID, connectionId *uuid.UUID) error {
|
func FileConnectionsAdd(ctx context.Context, metadataId *uuid.UUID, connectionId *uuid.UUID) error {
|
||||||
_, err := dbConn.Exec(ctx, `
|
_, err := dbConn.Exec(ctx, `
|
||||||
INSERT INTO file_connections (file_id, connection_id) VALUES ($1, $2)
|
INSERT INTO file_connections (file_id, connection_id) VALUES ($1, $2)
|
||||||
`, metadataId, connectionId)
|
`, metadataId, connectionId)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgFileConnectionsGet(ctx context.Context, metadata *types.FileMetadata) error {
|
func FileConnectionsGet(ctx context.Context, metadata *types.FileMetadata) error {
|
||||||
rows, err := dbConn.Query(ctx, `
|
rows, err := dbConn.Query(ctx, `
|
||||||
SELECT connection_id FROM file_connections WHERE file_id = $1
|
SELECT connection_id FROM file_connections WHERE file_id = $1
|
||||||
`, metadata.Id)
|
`, metadata.Id)
|
||||||
@@ -290,7 +290,7 @@ func PgFileConnectionsGet(ctx context.Context, metadata *types.FileMetadata) err
|
|||||||
return rows.Err()
|
return rows.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
func PgFileMetadataHashExists(ctx context.Context, hash *types.Sha256Hash) (bool, error) {
|
func FileMetadataHashExists(ctx context.Context, hash *types.Sha256Hash) (bool, error) {
|
||||||
var exists bool
|
var exists bool
|
||||||
err := dbConn.QueryRow(ctx, `
|
err := dbConn.QueryRow(ctx, `
|
||||||
SELECT EXISTS (SELECT FROM files_metadata WHERE hash = $1)
|
SELECT EXISTS (SELECT FROM files_metadata WHERE hash = $1)
|
||||||
|
|||||||
Reference in New Issue
Block a user