MCPcopy Index your code
hub / github.com/upper/db / TestPaginator_Issue607

Method TestPaginator_Issue607

internal/testsuite/sql_suite.go:1619–1702  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1617}
1618
1619func (s *SQLTestSuite) TestPaginator_Issue607() {
1620 sess := s.Session()
1621
1622 err := sess.Collection("artist").Truncate()
1623 s.NoError(err)
1624
1625 // Add first batch
1626 {
1627 batch := sess.SQL().InsertInto("artist").Batch(50)
1628
1629 go func() {
1630 defer batch.Done()
1631 for i := 0; i < 49; i++ {
1632 value := struct {
1633 Name string `db:"name"`
1634 }{fmt.Sprintf("artist-1.%d", i)}
1635 batch.Values(value)
1636 }
1637 }()
1638
1639 err = batch.Wait()
1640 s.NoError(err)
1641 s.NoError(batch.Err())
1642 }
1643
1644 artists := []*artistType{}
1645 paginator := sess.SQL().Select("name").From("artist").Paginate(10)
1646
1647 err = paginator.Page(1).All(&artists)
1648 s.NoError(err)
1649
1650 {
1651 totalPages, err := paginator.TotalPages()
1652 s.NoError(err)
1653 s.NotZero(totalPages)
1654 s.Equal(uint(5), totalPages)
1655 }
1656
1657 // Add second batch
1658 {
1659 batch := sess.SQL().InsertInto("artist").Batch(50)
1660
1661 go func() {
1662 defer batch.Done()
1663 for i := 0; i < 49; i++ {
1664 value := struct {
1665 Name string `db:"name"`
1666 }{fmt.Sprintf("artist-2.%d", i)}
1667 batch.Values(value)
1668 }
1669 }()
1670
1671 err = batch.Wait()
1672 s.NoError(err)
1673 s.NoError(batch.Err())
1674 }
1675
1676 {

Callers

nothing calls this directly

Calls 15

SessionMethod · 0.65
TruncateMethod · 0.65
CollectionMethod · 0.65
BatchMethod · 0.65
InsertIntoMethod · 0.65
SQLMethod · 0.65
DoneMethod · 0.65
ValuesMethod · 0.65
WaitMethod · 0.65
ErrMethod · 0.65
PaginateMethod · 0.65
FromMethod · 0.65

Tested by

no test coverage detected