MCPcopy Create free account
hub / github.com/gogs/gogs / dumpTable

Function dumpTable

internal/database/backup.go:75–108  ·  view source on GitHub ↗
(ctx context.Context, db *gorm.DB, table any, w io.Writer)

Source from the content-addressed store, hash-verified

73}
74
75func dumpTable(ctx context.Context, db *gorm.DB, table any, w io.Writer) error {
76 query := db.WithContext(ctx).Model(table)
77 switch table.(type) {
78 case *LFSObject:
79 query = query.Order("repo_id, oid ASC")
80 default:
81 query = query.Order("id ASC")
82 }
83
84 rows, err := query.Rows()
85 if err != nil {
86 return errors.Wrap(err, "select rows")
87 }
88 defer func() { _ = rows.Close() }()
89
90 for rows.Next() {
91 elem := reflect.New(reflect.TypeOf(table).Elem()).Interface()
92 err = db.ScanRows(rows, elem)
93 if err != nil {
94 return errors.Wrap(err, "scan rows")
95 }
96
97 switch e := elem.(type) {
98 case *LFSObject:
99 e.CreatedAt = e.CreatedAt.UTC()
100 }
101
102 err = jsoniter.NewEncoder(w).Encode(elem)
103 if err != nil {
104 return errors.Wrap(err, "encode JSON")
105 }
106 }
107 return rows.Err()
108}
109
110func dumpLegacyTables(ctx context.Context, dirPath string, verbose bool) error {
111 // Purposely create a local variable to not modify global variable

Callers 2

DumpDatabaseFunction · 0.85
dumpTablesFunction · 0.85

Calls 1

NextMethod · 0.45

Tested by 1

dumpTablesFunction · 0.68