morkid / paginate Goto Github PK
View Code? Open in Web Editor NEWpaginate - Gorm Pagination Library
Home Page: https://morkid.github.io/paginate/
License: MIT License
paginate - Gorm Pagination Library
Home Page: https://morkid.github.io/paginate/
License: MIT License
Hello,
The issue at hand is as follows.
Consider the following code:
query := fmt.Sprintf(`page=%d&size=%d`, 1, 5)
req := &http.Request{
Method: "GET",
URL: &url.URL{
RawQuery: query,
},
}
page := Pagination.With(resp).Request(req).Response(&result)
If the total number of records in our database is only 4, we won't receive anything in the response.
Please provide a solution. Thank you.
is it possible to limit max page size by server-side?
like i don't want to let user query data such as ?size=100000000
Hello dear friend,
According to the GORM documentation, the offset should be configured as follows:
https://gorm.io/docs/scopes.html#Pagination
offset := (page - 1) * pageSize
However, in your code, you have set it to:
https://github.com/morkid/paginate/blob/6a80ba937ff9c76f988630fe32526430da23a071/paginate.go#L334C2-L334C32
If the total number of records is 6, but our limit is 10, meaning the total number of records in the database is less than our limit, we encounter a problem in the response.
I would appreciate it if you could check this issue. Thank you for the excellent package you've developed; it's been very helpful.
I curious that any config to make get all record and not pagination ?
Hi, on posgres im trying to sort from a nested field from a join query.
?sort=Country.name
LEFT JOIN \"addresses\" \"Address\" ON \"accounts\".\"address_id\" = \"Address\".\"id\" WHERE \"accounts\".\"deleted_at\" IS NULL) AS s ORDER BY Country__name ASC LIMIT 50
"Country\".\"name\" AS \"Country__name\"
Still is throwing:
"error": "ERROR: column \"country__name\" does not exist (SQLSTATE 42703)"
I think the issue is on the generated query, the order by
shouldnt be inside the inner select ??
right now is doing:
SELECT count(*) FROM (SELECT........ ) as S ORDER BY Country_name ASC
shouldnt be like this ??
SELECT count(*) FROM (SELECT........ ORDER BY Country_name ASC) as S
Thanks!!
When passing a filter array like [["make", "like", "a"]]
I am receiving the following error:
.../go/pkg/mod/github.com/morkid/[email protected]/paginate.go:201 Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''\' ) )' at line 1
[3.546ms] [rows:0] SELECT count(1) FROM (SELECT * FROM `equipment` WHERE `equipment`.`deleted_at` IS NULL) AS s WHERE ( ( `make` LIKE '%a%' ESCAPE '\' ) )
The filters work fine when it is just [["make","a"]]
but that only returns exact matches. Any thoughts? Gorm database initialization looks like:
Database, _ = gorm.Open(mysql.Open(dsn), &gorm.Config{
Logger: logger.Default.LogMode(logger.Info),
})
example request : https://localhost:9900/api/v1/books?filters=[%22tr.id%22,%22bukhari%22]
can you give a key other than the dot value, so I can filter by lowercase reference.
Hi there, this seems to work fine as long as the ids of the paginated entities in questions are uints
.
I've implemented a custom data-type similar to this medium article that stores a BINARY(16) value as the id and provides helper methods to convert a string uuid to a BINARY(16) and back.
This paginate lib seems to have an issue with the implementation and I'm not sure why. I've got it working beautifully with entities with an INT primaryKey, but I get the following panic error with a BinaryUUID primaryKey:
2021/04/26 16:03:58 http: panic serving 127.0.0.1:61948: uuid: Parse(paginated): invalid UUID length: 9
goroutine 156 [running]:
net/http.(*conn).serve.func1(0xc0003c25a0)
/usr/local/Cellar/go/1.15.2/libexec/src/net/http/server.go:1801 +0x147
panic(0x1ca1340, 0xc000786a80)
/usr/local/Cellar/go/1.15.2/libexec/src/runtime/panic.go:975 +0x3e9
github.com/google/uuid.MustParse(0xc00024c52c, 0x9, 0x0, 0x0)
There is a ParseUUID function on the custom BinaryUUID
data type defined as follows:
func ParseUUID(id string) BinaryUUID {
fmt.Println("Attempting to parse: ", id)
return BinaryUUID(uuid.MustParse(id))
}
And the panic throws right after this function logs: "Attempting to parse: pagination". So for some reason, the string "pagination" is being interpreted as the id field of the selected entities? I'm not sure I understand 100% what is going on though.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.