func (m *GormCodebaseRepository) List(ctx context.Context, spaceID uuid.UUID, start *int, limit *int) ([]*Codebase, uint64, error) {
	defer goa.MeasureSince([]string{"goa", "db", "codebase", "query"}, time.Now())

	db := m.db.Model(&Codebase{}).Where("space_id = ?", spaceID)
	orgDB := db
	if start != nil {
		if *start < 0 {
			return nil, 0, errors.NewBadParameterError("start", *start)
		}
		db = db.Offset(*start)
	}
	if limit != nil {
		if *limit <= 0 {
			return nil, 0, errors.NewBadParameterError("limit", *limit)
		}
		db = db.Limit(*limit)
	}
	db = db.Select("count(*) over () as cnt2 , *")

	rows, err := db.Rows()
	if err != nil {
		return nil, 0, err
	}
	defer rows.Close()

	result := []*Codebase{}
	columns, err := rows.Columns()
	if err != nil {
		return nil, 0, errors.NewInternalError(err.Error())
	}

	// need to set up a result for Scan() in order to extract total count.
	var count uint64
	var ignore interface{}
	columnValues := make([]interface{}, len(columns))

	for index := range columnValues {
		columnValues[index] = &ignore
	}
	columnValues[0] = &count
	first := true

	for rows.Next() {
		value := &Codebase{}
		db.ScanRows(rows, value)
		if first {
			first = false
			if err = rows.Scan(columnValues...); err != nil {
				return nil, 0, errors.NewInternalError(err.Error())
			}
		}
		result = append(result, value)

	}
	if first {
		// means 0 rows were returned from the first query (maybe becaus of offset outside of total count),
		// need to do a count(*) to find out total
		orgDB := orgDB.Select("count(*)")
		rows2, err := orgDB.Rows()
		defer rows2.Close()
		if err != nil {
			return nil, 0, err
		}
		rows2.Next() // count(*) will always return a row
		rows2.Scan(&count)
	}
	return result, count, nil
}
// List all codebases related to a single item
List all codebases related to a single item
// List all codebases related to a single item
func (m *GormCodebaseRepository) List(ctx context.Context, spaceID uuid.UUID, start *int, limit *int) ([]*Codebase, uint64, error) {
	defer goa.MeasureSince([]string{"goa", "db", "codebase", "query"}, time.Now())
	db := m.db.Model(&Codebase{}).Where("space_id = ?", spaceID)
	orgDB := db
	if start != nil {
		if *start < 0 {
			return nil, 0, errors.NewBadParameterError("start", *start)
		}
		db = db.Offset(*start)
	}
	if limit != nil {
		if *limit <= 0 {
			return nil, 0, errors.NewBadParameterError("limit", *limit)
		}
		db = db.Limit(*limit)
	}
	db = db.Select("count(*) over () as cnt2 , *")
	rows, err := db.Rows()
	if err != nil {
		return nil, 0, err
	}
	defer rows.Close()
	result := []*Codebase{}
	columns, err := rows.Columns()
	if err != nil {
		return nil, 0, errors.NewInternalError(err.Error())
	}
	var count uint64
	var ignore interface{}
	columnValues := make([]interface{}, len(columns))
	for index := range columnValues {
		columnValues[index] = &ignore
	}
	columnValues[0] = &count
	first := true
	for rows.Next() {
		value := &Codebase{}
		db.ScanRows(rows, value)
		if first {
			first = false
			if err = rows.Scan(columnValues...); err != nil {
				return nil, 0, errors.NewInternalError(err.Error())
			}
		}
		result = append(result, value)
	}
	if first {
		orgDB := orgDB.Select("count(*)")
		rows2, err := orgDB.Rows()
		defer rows2.Close()
		if err != nil {
			return nil, 0, err
		}
		rows2.Next() 
		rows2.Scan(&count)
	}
	return result, count, nil
}
func ( m * GormCodebaseRepository ) List ( ctx context . Context , spaceID uuid . UUID , start * int , limit * int ) ( [ ] * Codebase , uint64 , error ) { defer goa . MeasureSince ( [ ] string { " " , " " , " " , " " } , time . Now ( ) ) db := m . db . Model ( & Codebase { } ) . Where ( " " , spaceID ) orgDB := db if start != nil { if * start < 0 { return nil , 0 , errors . NewBadParameterError ( " " , * start ) } db = db . Offset ( * start ) } if limit != nil { if * limit <= 0 { return nil , 0 , errors . NewBadParameterError ( " " , * limit ) } db = db . Limit ( * limit ) } db = db . Select ( " " ) rows , err := db . Rows ( ) if err != nil { return nil , 0 , err } defer rows . Close ( ) result := [ ] * Codebase { } columns , err := rows . Columns ( ) if err != nil { return nil , 0 , errors . NewInternalError ( err . Error ( ) ) } var count uint64 var ignore interface { } columnValues := make ( [ ] interface { } , len ( columns ) ) for index := range columnValues { columnValues [ index ] = & ignore } columnValues [ 0 ] = & count first := true for rows . Next ( ) { value := & Codebase { } db . ScanRows ( rows , value ) if first { first = false if err = rows . Scan ( columnValues ... ) ; err != nil { return nil , 0 , errors . NewInternalError ( err . Error ( ) ) } } result = append ( result , value ) } if first { orgDB := orgDB . Select ( " " ) rows2 , err := orgDB . Rows ( ) defer rows2 . Close ( ) if err != nil { return nil , 0 , err } rows2 . Next ( ) rows2 . Scan ( & count ) } return result , count , nil }
List all codebases related to a single item
List all codebases related to a single item
// need to set up a result for Scan() in order to extract total count. // means 0 rows were returned from the first query (maybe becaus of offset outside of total count), // need to do a count(*) to find out total // count(*) will always return a row