59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package postgres
|
|
|
|
import "context"
|
|
|
|
type terminalMapping struct {
|
|
ID int64 `gorm:"colunmn:id"`
|
|
Component string `gorm:"column:component"`
|
|
Tag string `gorm:"column:tag"`
|
|
// mapping TODO
|
|
}
|
|
|
|
func GetAllTerminalMapping(ctx context.Context, batchSize int) ([]*terminalMapping, error) {
|
|
var totalRecords []*terminalMapping
|
|
|
|
id := 0
|
|
for {
|
|
var records []*terminalMapping
|
|
result := client.WithContext(ctx).Table("terminal_mapping").Where("id > ?", id).
|
|
Order("id ASC").Limit(batchSize).Find(&records)
|
|
if result.Error != nil {
|
|
return totalRecords, result.Error
|
|
}
|
|
|
|
length := len(records)
|
|
if length <= 0 {
|
|
break
|
|
}
|
|
id += length
|
|
|
|
totalRecords = append(totalRecords, records...)
|
|
}
|
|
|
|
return totalRecords, nil
|
|
}
|
|
|
|
func GetStationTerminalMapping(ctx context.Context, batchSize int, station string) ([]*terminalMapping, error) {
|
|
var totalRecords []*terminalMapping
|
|
|
|
id := 0
|
|
for {
|
|
var records []*terminalMapping
|
|
result := client.WithContext(ctx).Table("terminal_mapping").Where("station = ?", station).
|
|
Where("id > ?", id).Order("id ASC").Limit(batchSize).Find(&records)
|
|
if result.Error != nil {
|
|
return totalRecords, result.Error
|
|
}
|
|
|
|
length := len(records)
|
|
if length <= 0 {
|
|
break
|
|
}
|
|
id += length
|
|
|
|
totalRecords = append(totalRecords, records...)
|
|
}
|
|
|
|
return totalRecords, nil
|
|
}
|