Getting Empty Records Back Using Golang, SQLC and PostgreSQL

I am trying to implement pagination in my GO backend API. The API uses SQLC
for the abstraction through to my PostgreSQL database. The issue is, It returns blank records and i cannot figure out what am doing wrong. The following are relevant codes pertaining to my current work:

  1. SQLC code:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>const getAllFeeds = `-- name: GetAllFeeds :many
SELECT count(*) OVER(), id, created_at, updated_at, name, url, user_id, version
FROM feeds
WHERE ($1 = '' OR to_tsvector('simple', name) @@ plainto_tsquery('simple', $1))
AND ($2 = '' OR url LIKE '%' || $2 || '%')
ORDER BY id ASC
LIMIT $3 OFFSET $4
`
type GetAllFeedsParams struct {
Column1 interface{}
Column2 interface{}
Limit int32
Offset int32
}
type GetAllFeedsRow struct {
Count int64
ID uuid.UUID
CreatedAt time.Time
UpdatedAt time.Time
Name string
Url string
UserID int64
Version int32
}
func (q *Queries) GetAllFeeds(ctx context.Context, arg GetAllFeedsParams) ([]GetAllFeedsRow, error) {
rows, err := q.db.QueryContext(ctx, getAllFeeds,
arg.Column1,
arg.Column2,
arg.Limit,
arg.Offset,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetAllFeedsRow
for rows.Next() {
var i GetAllFeedsRow
if err := rows.Scan(
&i.Count,
&i.ID,
&i.CreatedAt,
&i.UpdatedAt,
&i.Name,
&i.Url,
&i.UserID,
&i.Version,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
</code>
<code>const getAllFeeds = `-- name: GetAllFeeds :many SELECT count(*) OVER(), id, created_at, updated_at, name, url, user_id, version FROM feeds WHERE ($1 = '' OR to_tsvector('simple', name) @@ plainto_tsquery('simple', $1)) AND ($2 = '' OR url LIKE '%' || $2 || '%') ORDER BY id ASC LIMIT $3 OFFSET $4 ` type GetAllFeedsParams struct { Column1 interface{} Column2 interface{} Limit int32 Offset int32 } type GetAllFeedsRow struct { Count int64 ID uuid.UUID CreatedAt time.Time UpdatedAt time.Time Name string Url string UserID int64 Version int32 } func (q *Queries) GetAllFeeds(ctx context.Context, arg GetAllFeedsParams) ([]GetAllFeedsRow, error) { rows, err := q.db.QueryContext(ctx, getAllFeeds, arg.Column1, arg.Column2, arg.Limit, arg.Offset, ) if err != nil { return nil, err } defer rows.Close() var items []GetAllFeedsRow for rows.Next() { var i GetAllFeedsRow if err := rows.Scan( &i.Count, &i.ID, &i.CreatedAt, &i.UpdatedAt, &i.Name, &i.Url, &i.UserID, &i.Version, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } </code>
const getAllFeeds = `-- name: GetAllFeeds :many
SELECT count(*) OVER(), id, created_at, updated_at, name, url, user_id, version
FROM feeds
WHERE ($1 = '' OR to_tsvector('simple', name) @@ plainto_tsquery('simple', $1))
AND ($2 = '' OR url LIKE '%' || $2 || '%')
ORDER BY id ASC
LIMIT $3 OFFSET $4
`

type GetAllFeedsParams struct {
    Column1 interface{}
    Column2 interface{}
    Limit   int32
    Offset  int32
}

type GetAllFeedsRow struct {
    Count     int64
    ID        uuid.UUID
    CreatedAt time.Time
    UpdatedAt time.Time
    Name      string
    Url       string
    UserID    int64
    Version   int32
}

func (q *Queries) GetAllFeeds(ctx context.Context, arg GetAllFeedsParams) ([]GetAllFeedsRow, error) {
    rows, err := q.db.QueryContext(ctx, getAllFeeds,
        arg.Column1,
        arg.Column2,
        arg.Limit,
        arg.Offset,
    )
    if err != nil {
        return nil, err
    }
    defer rows.Close()
    var items []GetAllFeedsRow
    for rows.Next() {
        var i GetAllFeedsRow
        if err := rows.Scan(
            &i.Count,
            &i.ID,
            &i.CreatedAt,
            &i.UpdatedAt,
            &i.Name,
            &i.Url,
            &i.UserID,
            &i.Version,
        ); err != nil {
            return nil, err
        }
        items = append(items, i)
    }
    if err := rows.Close(); err != nil {
        return nil, err
    }
    if err := rows.Err(); err != nil {
        return nil, err
    }
    return items, nil
}
  1. Golang code:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>func (m FeedModel) GetAllFeeds(name string, url string, filters Filters) ([]*Feed, Metadata, error) {
// create our timeout context. All of them will just be 5 seconds
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// retrieve our data
fmt.Printf("Executing GetAllFeeds with name: [%s], url: [%s], limit: %d, offset: %dn",
name, url, filters.limit(), filters.offset())
rows, err := m.DB.GetAllFeeds(ctx, database.GetAllFeedsParams{
Column1: name,
Column2: sql.NullString{String: url, Valid: url != ""}, // Convert string to sql.NullString
Limit: int32(filters.limit()),
Offset: int32(filters.offset()),
})
//check for an error
if err != nil {
return nil, Metadata{}, err
}
fmt.Println("Rows: ", rows)
totalRecords := 0
feeds := []*Feed{}
for _, row := range rows {
var feed Feed
totalRecords = int(row.Count)
feed.ID = row.ID
feed.CreatedAt = row.CreatedAt
feed.UpdatedAt = row.UpdatedAt
feed.Name = row.Name
feed.Url = row.Url
feed.Version = row.Version
feed.UserID = row.UserID
feeds = append(feeds, &feed)
}
// Generate a Metadata struct, passing in the total record count and pagination
// parameters from the client.
metadata := calculateMetadata(totalRecords, filters.Page, filters.PageSize)
return feeds, metadata, nil
}
</code>
<code>func (m FeedModel) GetAllFeeds(name string, url string, filters Filters) ([]*Feed, Metadata, error) { // create our timeout context. All of them will just be 5 seconds ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() // retrieve our data fmt.Printf("Executing GetAllFeeds with name: [%s], url: [%s], limit: %d, offset: %dn", name, url, filters.limit(), filters.offset()) rows, err := m.DB.GetAllFeeds(ctx, database.GetAllFeedsParams{ Column1: name, Column2: sql.NullString{String: url, Valid: url != ""}, // Convert string to sql.NullString Limit: int32(filters.limit()), Offset: int32(filters.offset()), }) //check for an error if err != nil { return nil, Metadata{}, err } fmt.Println("Rows: ", rows) totalRecords := 0 feeds := []*Feed{} for _, row := range rows { var feed Feed totalRecords = int(row.Count) feed.ID = row.ID feed.CreatedAt = row.CreatedAt feed.UpdatedAt = row.UpdatedAt feed.Name = row.Name feed.Url = row.Url feed.Version = row.Version feed.UserID = row.UserID feeds = append(feeds, &feed) } // Generate a Metadata struct, passing in the total record count and pagination // parameters from the client. metadata := calculateMetadata(totalRecords, filters.Page, filters.PageSize) return feeds, metadata, nil } </code>
func (m FeedModel) GetAllFeeds(name string, url string, filters Filters) ([]*Feed, Metadata, error) {
    // create our timeout context. All of them will just be 5 seconds
    ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
    defer cancel()
    // retrieve our data
    fmt.Printf("Executing GetAllFeeds with name: [%s], url: [%s], limit: %d, offset: %dn",
        name, url, filters.limit(), filters.offset())

    rows, err := m.DB.GetAllFeeds(ctx, database.GetAllFeedsParams{
        Column1: name,
        Column2: sql.NullString{String: url, Valid: url != ""}, // Convert string to sql.NullString
        Limit:   int32(filters.limit()),
        Offset:  int32(filters.offset()),
    })
    //check for an error
    if err != nil {
        return nil, Metadata{}, err
    }
    fmt.Println("Rows: ", rows)
    totalRecords := 0
    feeds := []*Feed{}
    for _, row := range rows {
        var feed Feed
        totalRecords = int(row.Count)
        feed.ID = row.ID
        feed.CreatedAt = row.CreatedAt
        feed.UpdatedAt = row.UpdatedAt
        feed.Name = row.Name
        feed.Url = row.Url
        feed.Version = row.Version
        feed.UserID = row.UserID
        feeds = append(feeds, &feed)
    }
    // Generate a Metadata struct, passing in the total record count and pagination
    // parameters from the client.
    metadata := calculateMetadata(totalRecords, filters.Page, filters.PageSize)
    return feeds, metadata, nil
}

Sample output:
Executing GetAllFeeds with name: [], url: [], limit: 30, offset: 0 Rows: [] Total Records: 0
Initial schema:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>-- +goose Up
CREATE TABLE feeds(
id UUID PRIMARY KEY,
created_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
updated_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
name TEXT NOT NULL,
url TEXT UNIQUE NOT NULL,
version INT NOT NULL DEFAULT 1,
user_id bigserial NOT NULL REFERENCES users(id) ON DELETE CASCADE
);
</code>
<code>-- +goose Up CREATE TABLE feeds( id UUID PRIMARY KEY, created_at timestamp(0) with time zone NOT NULL DEFAULT NOW(), updated_at timestamp(0) with time zone NOT NULL DEFAULT NOW(), name TEXT NOT NULL, url TEXT UNIQUE NOT NULL, version INT NOT NULL DEFAULT 1, user_id bigserial NOT NULL REFERENCES users(id) ON DELETE CASCADE ); </code>
-- +goose Up
CREATE TABLE feeds(
    id UUID PRIMARY KEY,
        created_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
        updated_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
        name TEXT NOT NULL,
        url TEXT UNIQUE NOT NULL,
        version INT NOT NULL DEFAULT 1,
        user_id bigserial NOT NULL REFERENCES users(id) ON DELETE CASCADE
);

If I run the following directly in psql or even pgAdmin i get All records:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>SELECT count(*) OVER(), id, created_at, updated_at, name, url, user_id, version
FROM feeds
WHERE (to_tsvector('simple', name) @@ plainto_tsquery('simple','' ) OR ''= '')
AND (url LIKE '%' || '' || '%' OR '' = '')
ORDER BY id ASC
LIMIT 30 OFFSET 0;
</code>
<code>SELECT count(*) OVER(), id, created_at, updated_at, name, url, user_id, version FROM feeds WHERE (to_tsvector('simple', name) @@ plainto_tsquery('simple','' ) OR ''= '') AND (url LIKE '%' || '' || '%' OR '' = '') ORDER BY id ASC LIMIT 30 OFFSET 0; </code>
SELECT count(*) OVER(), id, created_at, updated_at, name, url, user_id, version
                FROM feeds
                WHERE (to_tsvector('simple', name) @@ plainto_tsquery('simple','' ) OR  ''= '')
                AND (url LIKE '%' || '' || '%' OR '' = '')
                ORDER BY id ASC
                LIMIT 30 OFFSET 0;

Now my question is, is there anything I may be missing since am getting empty results back using my own Golang code?. Just to add, I have my own functions that read the queries from the URL, so am sure on what is read. The offset and limit defaults to 0 and 30 if none is provided so the API returns all records.

Thank you in Advance.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật