-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
273 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package db | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/jackc/pgx/v4/pgxpool" | ||
|
||
"dev.maizy.ru/ponylib/fb2_parser" | ||
"dev.maizy.ru/ponylib/fb2_scanner/resource" | ||
) | ||
|
||
type BookResult struct { | ||
UUID string | ||
RId resource.RId | ||
Metadata fb2_parser.Fb2Metadata | ||
} | ||
|
||
func GetBook(conn *pgxpool.Pool, uuid string) (*BookResult, error) { | ||
var sqlQuery = "select id, rid, metadata from book where id = $1 limit 1" | ||
rows, err := conn.Query(context.Background(), sqlQuery, uuid) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to get book by uuid='%s': %w", uuid, err) | ||
} | ||
defer rows.Close() | ||
|
||
var uuidFromDb string | ||
var rawRId string | ||
var bookMetadata fb2_parser.Fb2Metadata | ||
rows.Next() | ||
if err := rows.Scan(&uuidFromDb, &rawRId, &bookMetadata); err != nil { | ||
return nil, fmt.Errorf("book with uuid='%s' not found", uuid) | ||
} | ||
|
||
bookRId, err := resource.DecodeRId(rawRId) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to deserialize RId for book with uuid='%s': %w", uuid, err) | ||
} | ||
|
||
return &BookResult{uuidFromDb, *bookRId, bookMetadata}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.