From c8a99ec17624d30bdff89eb08a82a253da4773c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B0=D1=82=D0=BE=D0=BB=D0=B8=D0=B9=20=D0=A2?= =?UTF-8?q?=D1=83=D1=85=D1=82=D0=B0=D1=80=D0=BE=D0=B2?= Date: Sat, 29 Jul 2023 07:29:58 +0500 Subject: [PATCH] v0.0.2 --- README.md | 3 ++- album.go | 9 +++++++++ db.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 5 +++++ go.sum | 9 +++++++++ picture.go | 23 +++++++++++++++++++++++ 6 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 album.go create mode 100644 db.go create mode 100644 go.sum diff --git a/README.md b/README.md index 4994df6..8a0d447 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,5 @@ pic - работа с картинками ## История -- 29-07-2023 Первый коммит \ No newline at end of file +- 29-07-2023 Первый коммит. +Сделал новый релиз для проверки \ No newline at end of file diff --git a/album.go b/album.go new file mode 100644 index 0000000..d8bb706 --- /dev/null +++ b/album.go @@ -0,0 +1,9 @@ +package pic + +// Album - работа с альбомами +type Album struct { + Seria string + Cnt int + Hash string +} + diff --git a/db.go b/db.go new file mode 100644 index 0000000..55900a7 --- /dev/null +++ b/db.go @@ -0,0 +1,51 @@ +package pic + +import ( + "strings" + + _ "github.com/go-sql-driver/mysql" // для связи с mysql + "github.com/jmoiron/sqlx" +) + +// возвращает список картинок одного альбома +func getAlbum(db *sqlx.DB, name string) ([]Picture, error) { + cmd := "call getOneSeria(?)" + var pics []Picture + err := db.Select(&pics, cmd, name) + return pics, err +} + +// возвращает список альбомов +func getAlbums(db *sqlx.DB) ([]Album, error) { + cmd := "call getAlbums()" + var albums []Album + err := db.Select(&albums, cmd) + return albums, err +} + +// устанавливает признак удаленной картинки в БД +func deleteImagesDB(db *sqlx.DB, ids []int) error { + cmd := "UPDATE filemeta SET del = 1 WHERE id = ?" + for _, id := range ids { + _, err := db.Exec(cmd, id) + if err != nil { + return err + } + } + return nil +} + +// перемещает картинки в альбом +func moveImagesDB(db *sqlx.DB, newseria, ids string) error { + cmd := "UPDATE pic SET seria = ? WHERE file_id = ?" + // fmt.Printf("перемещаю: %v в %s\n", ids, newseria) + list := strings.Split(ids, ",") + for _, id := range list { + _, err := db.Exec(cmd, newseria, id) + if err != nil { + return err + } + // fmt.Printf(" ==перемещаю: %s в %s\n", id, newseria) + } + return nil +} diff --git a/go.mod b/go.mod index 993e018..02ae96b 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,8 @@ module github.com/tad17/pic go 1.19 + +require ( + github.com/go-sql-driver/mysql v1.7.1 + github.com/jmoiron/sqlx v1.3.5 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..aa856f1 --- /dev/null +++ b/go.sum @@ -0,0 +1,9 @@ +github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= +github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g= +github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ= +github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0= +github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg= +github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= diff --git a/picture.go b/picture.go index d181150..8d02dae 100644 --- a/picture.go +++ b/picture.go @@ -2,8 +2,31 @@ package pic import ( "fmt" + "github.com/jmoiron/sqlx" ) +//Picture работа с картинкаи +type Picture struct { + ID int `json:"id"` + Url string `json:"src"` + Width int `json:"width"` + Height int `json:"height"` + Thumb string `json:"srct"` + ThumbWidth int `db:"thumb_width" json:"imgtWidth"` + ThumbHeight int `db:"thumb_height" json:"imgtHeight"` + + // закрытые поля + db *sqlx.DB + album string +} + +//Hello - приветствие и комментарии к модулю func Hello() { fmt.Printf("pic - пакет для работы с картинками\n") + fmt.Printf("v0.0.1 - начальная версия\n") +} + +func NewPicture(db *sqlx.DB, album string) Picture { + pic := Picture {db: db, album: album} + return pic } \ No newline at end of file