diff --git a/go.mod b/go.mod index 6a608c5..a457531 100644 --- a/go.mod +++ b/go.mod @@ -5,16 +5,20 @@ go 1.12 require ( github.com/PuerkitoBio/goquery v1.5.1 github.com/araddon/dateparse v0.0.0-20190622164848-0fb0a474d195 // indirect + github.com/cockroachdb/apd v1.1.0 // indirect github.com/fatih/set v0.2.1 // indirect github.com/gigawattio/window v0.0.0-20180317192513-0f5467e35573 // indirect github.com/go-sql-driver/mysql v1.4.1 // indirect + github.com/gofrs/uuid v3.2.0+incompatible // indirect github.com/gorilla/websocket v1.4.0 // indirect github.com/ikawaha/kagome v1.11.2 + github.com/jackc/fake v0.0.0-20150926172116-812a484cc733 // indirect + github.com/jackc/pgx v3.6.2+incompatible github.com/jaytaylor/html2text v0.0.0-20190408195923-01ec452cbe43 // indirect github.com/jdkato/prose v0.0.0-20181022194337-a179b97cfa6f github.com/jmoiron/sqlx v1.2.0 github.com/kylelemons/godebug v1.1.0 // indirect - github.com/lib/pq v1.3.0 + github.com/lib/pq v1.3.0 // indirect github.com/mackerelio/mackerel-client-go v0.9.1 github.com/mattn/go-isatty v0.0.8 // indirect github.com/mattn/go-runewidth v0.0.4 // indirect @@ -27,6 +31,7 @@ require ( github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 github.com/pkg/errors v0.9.1 github.com/shogo82148/go-shuffle v0.0.0-20180218125048-27e6095f230d // indirect + github.com/shopspring/decimal v0.0.0-20200419222939-1884f454f8ea // indirect github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect github.com/stretchr/testify v1.3.0 // indirect github.com/syou6162/GoOse v0.0.0-20190108170554-09969ebeb09f diff --git a/go.sum b/go.sum index 7ed2435..ca7eb6b 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/andybalholm/cascadia v1.1.0 h1:BuuO6sSfQNFRu1LppgbD25Hr2vLYW25JvxHs5z github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= github.com/araddon/dateparse v0.0.0-20190622164848-0fb0a474d195 h1:c4mLfegoDw6OhSJXTd2jUEQgZUQuJWtocudb97Qn9EM= github.com/araddon/dateparse v0.0.0-20190622164848-0fb0a474d195/go.mod h1:SLqhdZcd+dF3TEVL2RMoob5bBP5R1P1qkox+HtCBgGI= +github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I= +github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= @@ -19,12 +21,18 @@ github.com/go-sql-driver/mysql v1.4.0 h1:7LxgVwFb2hIQtMm87NdgAVfXjnt4OePseqT1tKx github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= +github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE= +github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/ikawaha/kagome v1.11.2 h1:eCWpLqv5Euqa5JcwkaobUSy6uGM8rwwMw5Su3eRepBI= github.com/ikawaha/kagome v1.11.2/go.mod h1:lHwhkGuuWqKWTxeQMppD0EmQAfKbc39QKx9qoWqgo+A= +github.com/jackc/fake v0.0.0-20150926172116-812a484cc733 h1:vr3AYkKovP8uR8AvSGGUK1IDqRa5lAAvEkZG1LKaCRc= +github.com/jackc/fake v0.0.0-20150926172116-812a484cc733/go.mod h1:WrMFNQdiFJ80sQsxDoMokWK1W5TQtxBFNpzWTD84ibQ= +github.com/jackc/pgx v3.6.2+incompatible h1:2zP5OD7kiyR3xzRYMhOcXVvkDZsImVXfj+yIyTQf3/o= +github.com/jackc/pgx v3.6.2+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I= github.com/jaytaylor/html2text v0.0.0-20190408195923-01ec452cbe43 h1:jTkyeF7NZ5oIr0ESmcrpiDgAfoidCBF4F5kJhjtaRwE= github.com/jaytaylor/html2text v0.0.0-20190408195923-01ec452cbe43/go.mod h1:CVKlgaMiht+LXvHG173ujK6JUhZXKb2u/BQtjPDIvyk= github.com/jdkato/prose v0.0.0-20181022194337-a179b97cfa6f h1:AQ+AwWeEFf6NsjaMzhuVKLfxZH1+i7aoHuYXObQAzDo= @@ -69,6 +77,8 @@ github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shogo82148/go-shuffle v0.0.0-20180218125048-27e6095f230d h1:rUbV6LJa5RXK3jT/4jnJUz3UkrXzW6cqB+n9Fkbv9jY= github.com/shogo82148/go-shuffle v0.0.0-20180218125048-27e6095f230d/go.mod h1:2htx6lmL0NGLHlO8ZCf+lQBGBHIbEujyywxJArf+2Yc= +github.com/shopspring/decimal v0.0.0-20200419222939-1884f454f8ea h1:jaXWVFZ98/ihXniiDzqNXQgMSgklX4kjfDWZTE3ZtdU= +github.com/shopspring/decimal v0.0.0-20200419222939-1884f454f8ea/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf h1:pvbZ0lM0XWPBqUKqFU8cmavspvIl9nulOYwdy6IFRRo= diff --git a/lib/repository/example.go b/lib/repository/example.go index 140f841..f5e244a 100644 --- a/lib/repository/example.go +++ b/lib/repository/example.go @@ -7,7 +7,7 @@ import ( "io" "time" - "github.com/lib/pq" + "github.com/jackc/pgx" "github.com/syou6162/go-active-learning/lib/feature" "github.com/syou6162/go-active-learning/lib/model" "github.com/syou6162/go-active-learning/lib/util/file" @@ -89,7 +89,7 @@ func (r *repository) UpdateFeatureVector(e *model.Example) error { if _, err = r.db.Exec(`DELETE FROM feature WHERE example_id = $1;`, id); err != nil { return err } - _, err = r.db.Exec(`INSERT INTO feature (example_id, feature) VALUES ($1, unnest(cast($2 AS TEXT[])));`, id, pq.Array(e.Fv)) + _, err = r.db.Exec(`INSERT INTO feature (example_id, feature) VALUES ($1, unnest(cast($2 AS TEXT[])));`, id, pgx.Array(e.Fv)) return err } @@ -214,7 +214,7 @@ func (r *repository) FindExampleById(id int) (*model.Example, error) { func (r *repository) SearchExamplesByUlrs(urls []string) (model.Examples, error) { // ref: https://godoc.org/github.com/lib/pq#Array query := `SELECT * FROM example WHERE url = ANY($1);` - return r.searchExamples(query, pq.Array(urls)) + return r.searchExamples(query, pgx.Array(urls)) } func (r *repository) SearchExamplesByIds(ids []int) (model.Examples, error) { @@ -222,7 +222,7 @@ func (r *repository) SearchExamplesByIds(ids []int) (model.Examples, error) { return model.Examples{}, nil } query := fmt.Sprintf(`%s FROM example WHERE id = ANY($1);`, buildSelectQuery(true)) - return r.searchExamples(query, pq.Array(ids)) + return r.searchExamples(query, pgx.Array(ids)) } func (r *repository) SearchExamplesByKeywords(keywords []string, aggregator string, limit int) (model.Examples, error) { @@ -234,7 +234,7 @@ func (r *repository) SearchExamplesByKeywords(keywords []string, aggregator stri regexList = append(regexList, fmt.Sprintf(`.*%s.*`, w)) } query := fmt.Sprintf(`%s FROM example WHERE title ~* %s($1) AND label != -1 ORDER BY (label, score) DESC LIMIT $2;`, buildSelectQuery(true), aggregator) - return r.searchExamples(query, pq.Array(regexList), limit) + return r.searchExamples(query, pgx.Array(regexList), limit) } func (r *repository) countExamplesByLabel(label model.LabelType) (int, error) { @@ -296,7 +296,7 @@ func (r *repository) SearchFeatureVector(examples model.Examples) (map[int]featu query := `SELECT example_id, feature FROM feature WHERE example_id = ANY($1);` pairs := make([]Pair, 0) - err = r.db.Select(&pairs, query, pq.Array(ids)) + err = r.db.Select(&pairs, query, pgx.Array(ids)) if err != nil { return fvById, err } diff --git a/lib/repository/hatena_bookmark.go b/lib/repository/hatena_bookmark.go index 936d148..74a8846 100644 --- a/lib/repository/hatena_bookmark.go +++ b/lib/repository/hatena_bookmark.go @@ -1,7 +1,7 @@ package repository import ( - "github.com/lib/pq" + "github.com/jackc/pgx" "github.com/syou6162/go-active-learning/lib/model" ) @@ -59,7 +59,7 @@ func (r *repository) SearchHatenaBookmarks(examples model.Examples, limitForEach } query := `SELECT * FROM hatena_bookmark WHERE example_id = ANY($1);` - err := r.db.Select(&hatenaBookmarks, query, pq.Array(exampleIds)) + err := r.db.Select(&hatenaBookmarks, query, pgx.Array(exampleIds)) if err != nil { return hatenaBookmarks, err } @@ -75,7 +75,7 @@ func (r *repository) SearchHatenaBookmarks(examples model.Examples, limitForEach bookmarks := make([]*model.Bookmark, 0) query = `SELECT * FROM bookmark WHERE hatena_bookmark_id = ANY($1) ORDER BY timestamp LIMIT $2;` - err = r.db.Select(&bookmarks, query, pq.Array(hatenaBookmarkIds), limitForEachExample) + err = r.db.Select(&bookmarks, query, pgx.Array(hatenaBookmarkIds), limitForEachExample) if err != nil { return hatenaBookmarks, err } diff --git a/lib/repository/recommendation.go b/lib/repository/recommendation.go index 47c7e9e..1a485d0 100644 --- a/lib/repository/recommendation.go +++ b/lib/repository/recommendation.go @@ -1,7 +1,7 @@ package repository import ( - "github.com/lib/pq" + "github.com/jackc/pgx" "github.com/syou6162/go-active-learning/lib/model" ) @@ -9,7 +9,7 @@ func (r *repository) UpdateRecommendation(rec model.Recommendation) error { if _, err := r.db.Exec(`DELETE FROM recommendation WHERE list_type = $1;`, rec.RecommendationListType); err != nil { return err } - if _, err := r.db.Exec(`INSERT INTO recommendation (list_type, example_id) VALUES ($1, unnest(cast($2 AS INT[])));`, rec.RecommendationListType, pq.Array(rec.ExampleIds)); err != nil { + if _, err := r.db.Exec(`INSERT INTO recommendation (list_type, example_id) VALUES ($1, unnest(cast($2 AS INT[])));`, rec.RecommendationListType, pgx.Array(rec.ExampleIds)); err != nil { return err } return nil diff --git a/lib/repository/related_example.go b/lib/repository/related_example.go index ce7f259..a60b07d 100644 --- a/lib/repository/related_example.go +++ b/lib/repository/related_example.go @@ -1,7 +1,7 @@ package repository import ( - "github.com/lib/pq" + "github.com/jackc/pgx" "github.com/syou6162/go-active-learning/lib/model" ) @@ -9,7 +9,7 @@ func (r *repository) UpdateRelatedExamples(related model.RelatedExamples) error if _, err := r.db.Exec(`DELETE FROM related_example WHERE example_id = $1;`, related.ExampleId); err != nil { return err } - if _, err := r.db.Exec(`INSERT INTO related_example (example_id, related_example_id) VALUES ($1, unnest(cast($2 AS INT[])));`, related.ExampleId, pq.Array(related.RelatedExampleIds)); err != nil { + if _, err := r.db.Exec(`INSERT INTO related_example (example_id, related_example_id) VALUES ($1, unnest(cast($2 AS INT[])));`, related.ExampleId, pgx.Array(related.RelatedExampleIds)); err != nil { return err } return nil diff --git a/lib/repository/repository.go b/lib/repository/repository.go index f72ac37..4d9440a 100644 --- a/lib/repository/repository.go +++ b/lib/repository/repository.go @@ -9,7 +9,7 @@ import ( "bufio" - _ "github.com/lib/pq" + _ "github.com/jackc/pgx" "github.com/syou6162/go-active-learning/lib/classifier" "github.com/syou6162/go-active-learning/lib/feature" "github.com/syou6162/go-active-learning/lib/model" diff --git a/lib/repository/top_accessed_example.go b/lib/repository/top_accessed_example.go index 3f4a630..f70bbca 100644 --- a/lib/repository/top_accessed_example.go +++ b/lib/repository/top_accessed_example.go @@ -1,14 +1,14 @@ package repository import ( - "github.com/lib/pq" + "github.com/jackc/pgx" ) func (r *repository) UpdateTopAccessedExampleIds(exampleIds []int) error { if _, err := r.db.Exec(`DELETE FROM top_accessed_example;`); err != nil { return err } - if _, err := r.db.Exec(`INSERT INTO top_accessed_example (example_id) VALUES (unnest(cast($1 AS INT[])));`, pq.Array(exampleIds)); err != nil { + if _, err := r.db.Exec(`INSERT INTO top_accessed_example (example_id) VALUES (unnest(cast($1 AS INT[])));`, pgx.Array(exampleIds)); err != nil { return err } return nil diff --git a/lib/repository/tweet.go b/lib/repository/tweet.go index 3b7c7a3..bb249b8 100644 --- a/lib/repository/tweet.go +++ b/lib/repository/tweet.go @@ -3,7 +3,7 @@ package repository import ( "time" - "github.com/lib/pq" + "github.com/jackc/pgx" "github.com/syou6162/go-active-learning/lib/model" ) @@ -59,7 +59,7 @@ func (r *repository) SearchReferringTweetsList(examples model.Examples, limitFor exampleIdsWithTweetsCount := make([]exampleIdWithTweetsCount, 0) tweetsCountByExampleQuery := `SELECT example_id, COUNT(*) AS tweets_count FROM tweet WHERE example_id = ANY($1) GROUP BY example_id ORDER BY tweets_count DESC;` - err := r.db.Select(&exampleIdsWithTweetsCount, tweetsCountByExampleQuery, pq.Array(exampleIds)) + err := r.db.Select(&exampleIdsWithTweetsCount, tweetsCountByExampleQuery, pgx.Array(exampleIds)) if err != nil { return referringTweetsByExampleId, err } @@ -81,7 +81,7 @@ func (r *repository) SearchReferringTweetsList(examples model.Examples, limitFor tweets := make([]*model.Tweet, 0) query := `SELECT * FROM tweet WHERE example_id = ANY($1) AND label != -1 AND score > -1.0 AND (lang = 'en' OR lang = 'ja') ORDER BY favorite_count DESC LIMIT $2;` - err = r.db.Select(&tweets, query, pq.Array(exampleIds), limitForEachExample) + err = r.db.Select(&tweets, query, pgx.Array(exampleIds), limitForEachExample) if err != nil { return referringTweetsByExampleId, err }