Query runs a SELECT, paging by gocql PageState/PageSize, and returns rows with gocql-native types normalized to portable Go values.
(ctx context.Context, stmt Statement)
| 23 | // Query runs a SELECT, paging by gocql PageState/PageSize, and returns rows with |
| 24 | // gocql-native types normalized to portable Go values. |
| 25 | func (e *gocqlExecutor) Query(ctx context.Context, stmt Statement) (ResultSet, error) { |
| 26 | q := e.session.Query(stmt.CQL, stmt.Args...).WithContext(ctx).Idempotent(stmt.Idempotent) |
| 27 | if stmt.PageSize > 0 { |
| 28 | q = q.PageSize(stmt.PageSize) |
| 29 | } |
| 30 | if len(stmt.PageState) > 0 { |
| 31 | q = q.PageState(stmt.PageState) |
| 32 | } |
| 33 | iter := q.Iter() |
| 34 | |
| 35 | var rows []map[string]any |
| 36 | if stmt.PageSize > 0 { |
| 37 | // Read exactly the current page. Calling MapScan past NumRows would make |
| 38 | // gocql transparently fetch the next page, defeating cursor pagination. |
| 39 | n := iter.NumRows() |
| 40 | for i := 0; i < n; i++ { |
| 41 | raw := make(map[string]any) |
| 42 | if !iter.MapScan(raw) { |
| 43 | break |
| 44 | } |
| 45 | rows = append(rows, normalizeRow(raw)) |
| 46 | } |
| 47 | } else { |
| 48 | for { |
| 49 | raw := make(map[string]any) |
| 50 | if !iter.MapScan(raw) { |
| 51 | break |
| 52 | } |
| 53 | rows = append(rows, normalizeRow(raw)) |
| 54 | } |
| 55 | } |
| 56 | next := iter.PageState() |
| 57 | if err := iter.Close(); err != nil { |
| 58 | return ResultSet{}, fmt.Errorf("cassandradriver: query failed: %w", err) |
| 59 | } |
| 60 | page := make([]byte, len(next)) |
| 61 | copy(page, next) // gocql reuses its buffer; copy before it's recycled |
| 62 | return ResultSet{Rows: rows, PageState: page}, nil |
| 63 | } |
| 64 | |
| 65 | // Exec runs a write. The applied/page state of an LWT is not surfaced in v1. |
| 66 | func (e *gocqlExecutor) Exec(ctx context.Context, stmt Statement) (ResultSet, error) { |
nothing calls this directly
no test coverage detected