github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/query/queryresult/result.go (about)

     1  package queryresult
     2  
     3  type TimingResult struct {
     4  	DurationMs          int64              `json:"duration_ms"`
     5  	Scans               []*ScanMetadataRow `json:"scans"`
     6  	ScanCount           int64              `json:"scan_count,omitempty"`
     7  	RowsReturned        int64              `json:"rows_returned"`
     8  	UncachedRowsFetched int64              `json:"uncached_rows_fetched"`
     9  	CachedRowsFetched   int64              `json:"cached_rows_fetched"`
    10  	HydrateCalls        int64              `json:"hydrate_calls"`
    11  	ConnectionCount     int64              `json:"connection_count"`
    12  }
    13  
    14  func (r *TimingResult) Initialise(summary *QueryRowSummary, scans []*ScanMetadataRow) {
    15  	r.ScanCount = summary.ScanCount
    16  	r.ConnectionCount = summary.ConnectionCount
    17  	r.UncachedRowsFetched = summary.UncachedRowsFetched
    18  	r.CachedRowsFetched = summary.CachedRowsFetched
    19  	r.HydrateCalls = summary.HydrateCalls
    20  	// populate scans - note this may not be all scans
    21  	r.Scans = scans
    22  }
    23  
    24  type RowResult struct {
    25  	Data  []interface{}
    26  	Error error
    27  }
    28  type Result struct {
    29  	RowChan      *chan *RowResult
    30  	Cols         []*ColumnDef
    31  	TimingResult chan *TimingResult
    32  }
    33  
    34  func NewResult(cols []*ColumnDef) *Result {
    35  	rowChan := make(chan *RowResult)
    36  	return &Result{
    37  		RowChan:      &rowChan,
    38  		Cols:         cols,
    39  		TimingResult: make(chan *TimingResult, 1),
    40  	}
    41  }
    42  
    43  // IsExportSourceData implements ExportSourceData
    44  func (*Result) IsExportSourceData() {}
    45  
    46  // Close closes the row channel
    47  func (r *Result) Close() {
    48  	close(*r.RowChan)
    49  }
    50  
    51  func (r *Result) StreamRow(rowResult []interface{}) {
    52  	*r.RowChan <- &RowResult{Data: rowResult}
    53  }
    54  func (r *Result) StreamError(err error) {
    55  	*r.RowChan <- &RowResult{Error: err}
    56  }
    57  
    58  type SyncQueryResult struct {
    59  	Rows         []interface{}
    60  	Cols         []*ColumnDef
    61  	TimingResult *TimingResult
    62  }