MCPcopy
hub / github.com/wavetermdev/waveterm / DBGetSingletonByType

Function DBGetSingletonByType

pkg/wstore/wstore_dbops.go:107–123  ·  view source on GitHub ↗
(ctx context.Context, otype string)

Source from the content-addressed store, hash-verified

105}
106
107func DBGetSingletonByType(ctx context.Context, otype string) (waveobj.WaveObj, error) {
108 return WithTxRtn(ctx, func(tx *TxWrap) (waveobj.WaveObj, error) {
109 table := tableNameFromOType(otype)
110 query := fmt.Sprintf("SELECT oid, version, data FROM %s LIMIT 1", table)
111 var row idDataType
112 found := tx.Get(&row, query)
113 if !found {
114 return nil, ErrNotFound
115 }
116 rtn, err := waveobj.FromJson(row.Data)
117 if err != nil {
118 return rtn, err
119 }
120 waveobj.SetVersion(rtn, row.Version)
121 return rtn, nil
122 })
123}
124
125func DBExistsORef(ctx context.Context, oref waveobj.ORef) (bool, error) {
126 return WithTxRtn(ctx, func(tx *TxWrap) (bool, error) {

Callers 1

DBGetSingletonFunction · 0.85

Calls 5

FromJsonFunction · 0.92
SetVersionFunction · 0.92
tableNameFromOTypeFunction · 0.85
WithTxRtnFunction · 0.70
GetMethod · 0.45

Tested by

no test coverage detected