分表
This commit is contained in:
+37
-13
@@ -35,22 +35,54 @@ func normalizeListOptions(opts listOptions) listOptions {
|
||||
return opts
|
||||
}
|
||||
|
||||
func (s *store) ListNodes(opts listOptions) ([]nodeInfoMapRecord, error) {
|
||||
func (s *store) ListNodeInfo(opts listOptions) ([]nodeInfoRecord, error) {
|
||||
opts = normalizeListOptions(opts)
|
||||
var rows []nodeInfoMapRecord
|
||||
q := applyNodeFilters(s.db.Model(&nodeInfoMapRecord{}), opts).
|
||||
var rows []nodeInfoRecord
|
||||
q := applyNodeFilters(s.db.Model(&nodeInfoRecord{}), opts).
|
||||
Order("updated_at DESC").
|
||||
Limit(opts.Limit).
|
||||
Offset(opts.Offset)
|
||||
return rows, q.Find(&rows).Error
|
||||
}
|
||||
|
||||
func (s *store) CountNodes(opts listOptions) (int64, error) {
|
||||
func (s *store) CountNodeInfo(opts listOptions) (int64, error) {
|
||||
var total int64
|
||||
q := applyNodeFilters(s.db.Model(&nodeInfoMapRecord{}), opts)
|
||||
q := applyNodeFilters(s.db.Model(&nodeInfoRecord{}), opts)
|
||||
return total, q.Count(&total).Error
|
||||
}
|
||||
|
||||
func (s *store) GetNodeInfo(nodeID string) (*nodeInfoRecord, error) {
|
||||
var row nodeInfoRecord
|
||||
if err := s.db.Where("node_id = ?", nodeID).Take(&row).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &row, nil
|
||||
}
|
||||
|
||||
func (s *store) ListMapReports(opts listOptions) ([]mapReportRecord, error) {
|
||||
opts = normalizeListOptions(opts)
|
||||
var rows []mapReportRecord
|
||||
q := applyNodeFilters(s.db.Model(&mapReportRecord{}), opts).
|
||||
Order("updated_at DESC").
|
||||
Limit(opts.Limit).
|
||||
Offset(opts.Offset)
|
||||
return rows, q.Find(&rows).Error
|
||||
}
|
||||
|
||||
func (s *store) CountMapReports(opts listOptions) (int64, error) {
|
||||
var total int64
|
||||
q := applyNodeFilters(s.db.Model(&mapReportRecord{}), opts)
|
||||
return total, q.Count(&total).Error
|
||||
}
|
||||
|
||||
func (s *store) GetMapReport(nodeID string) (*mapReportRecord, error) {
|
||||
var row mapReportRecord
|
||||
if err := s.db.Where("node_id = ?", nodeID).Take(&row).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &row, nil
|
||||
}
|
||||
|
||||
func applyNodeFilters(q *gorm.DB, opts listOptions) *gorm.DB {
|
||||
if opts.NodeID != "" {
|
||||
q = q.Where("node_id = ?", opts.NodeID)
|
||||
@@ -64,14 +96,6 @@ func applyNodeFilters(q *gorm.DB, opts listOptions) *gorm.DB {
|
||||
return q
|
||||
}
|
||||
|
||||
func (s *store) GetNode(nodeID string) (*nodeInfoMapRecord, error) {
|
||||
var row nodeInfoMapRecord
|
||||
if err := s.db.Where("node_id = ?", nodeID).Take(&row).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &row, nil
|
||||
}
|
||||
|
||||
func (s *store) ListTextMessages(opts listOptions) ([]textMessageRecord, error) {
|
||||
var rows []textMessageRecord
|
||||
return rows, s.listAppendRows(opts, &rows).Error
|
||||
|
||||
Reference in New Issue
Block a user