Giter Site home page Giter Site logo

morkid / paginate Goto Github PK

View Code? Open in Web Editor NEW
94.0 4.0 16.0 60 KB

paginate - Gorm Pagination Library

Home Page: https://morkid.github.io/paginate/

License: MIT License

Go 100.00%
gorm golang jquery-select2 fasthttp jquery-datatable elasticsearch pagination paginate-gorm paginate database

paginate's People

Contributors

http502 avatar morkid avatar pedrofurtado avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

paginate's Issues

Limit size

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

Request for Change: query.Offset = p.Page * p.Size to query.Offset = (p.Page - 1) * p.Size

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.

Sorting using nested field

Hi, on posgres im trying to sort from a nested field from a join query.

  • on the querystring i have ?sort=Country.name
  • on the query the clause look ok, the name is correctly camelized
    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
  • and also the Country_name column name is being generated correctly "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!!

MySQL syntax near ''\' ) )'

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),
})

UUID issue

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.