添加主DB的Context存储
This commit is contained in:
parent
0e4226fd84
commit
10cdd32e95
6
model.go
6
model.go
|
@ -391,6 +391,7 @@ func (m *Model) Search(w http.ResponseWriter, r *http.Request) {
|
||||||
ModuleName: m.naming.ModuleName,
|
ModuleName: m.naming.ModuleName,
|
||||||
TableName: m.naming.TableName,
|
TableName: m.naming.TableName,
|
||||||
Scenario: types.ScenarioList,
|
Scenario: types.ScenarioList,
|
||||||
|
Context: m.db.Statement.Context,
|
||||||
})
|
})
|
||||||
if searchSchemas, err = m.schemaLookup(childCtx, m.getDB(), domainName, m.naming.ModuleName, m.naming.TableName, types.ScenarioSearch); err != nil {
|
if searchSchemas, err = m.schemaLookup(childCtx, m.getDB(), domainName, m.naming.ModuleName, m.naming.TableName, types.ScenarioSearch); err != nil {
|
||||||
m.response.Failure(w, types.RequestRecordNotFound, "record not found", nil)
|
m.response.Failure(w, types.RequestRecordNotFound, "record not found", nil)
|
||||||
|
@ -496,6 +497,7 @@ func (m *Model) Create(w http.ResponseWriter, r *http.Request) {
|
||||||
TableName: m.naming.TableName,
|
TableName: m.naming.TableName,
|
||||||
Scenario: types.ScenarioCreate,
|
Scenario: types.ScenarioCreate,
|
||||||
Schemas: schemas,
|
Schemas: schemas,
|
||||||
|
Context: m.db.Statement.Context,
|
||||||
})
|
})
|
||||||
dbSess := m.getDB().WithContext(childCtx)
|
dbSess := m.getDB().WithContext(childCtx)
|
||||||
if err = dbSess.Transaction(func(tx *gorm.DB) (errTx error) {
|
if err = dbSess.Transaction(func(tx *gorm.DB) (errTx error) {
|
||||||
|
@ -594,6 +596,7 @@ func (m *Model) Update(w http.ResponseWriter, r *http.Request) {
|
||||||
Scenario: types.ScenarioUpdate,
|
Scenario: types.ScenarioUpdate,
|
||||||
Schemas: schemas,
|
Schemas: schemas,
|
||||||
PrimaryKeyValue: idStr,
|
PrimaryKeyValue: idStr,
|
||||||
|
Context: m.db.Statement.Context,
|
||||||
})
|
})
|
||||||
dbSess := m.getDB().WithContext(childCtx)
|
dbSess := m.getDB().WithContext(childCtx)
|
||||||
if err = dbSess.Transaction(func(tx *gorm.DB) (errTx error) {
|
if err = dbSess.Transaction(func(tx *gorm.DB) (errTx error) {
|
||||||
|
@ -677,6 +680,7 @@ func (m *Model) Delete(w http.ResponseWriter, r *http.Request) {
|
||||||
TableName: m.naming.TableName,
|
TableName: m.naming.TableName,
|
||||||
Scenario: types.ScenarioDelete,
|
Scenario: types.ScenarioDelete,
|
||||||
PrimaryKeyValue: idStr,
|
PrimaryKeyValue: idStr,
|
||||||
|
Context: m.db.Statement.Context,
|
||||||
})
|
})
|
||||||
dbSess := m.getDB().WithContext(childCtx)
|
dbSess := m.getDB().WithContext(childCtx)
|
||||||
if err = dbSess.Transaction(func(tx *gorm.DB) (errTx error) {
|
if err = dbSess.Transaction(func(tx *gorm.DB) (errTx error) {
|
||||||
|
@ -794,6 +798,7 @@ func (m *Model) Export(w http.ResponseWriter, r *http.Request) {
|
||||||
ModuleName: m.naming.ModuleName,
|
ModuleName: m.naming.ModuleName,
|
||||||
TableName: m.naming.TableName,
|
TableName: m.naming.TableName,
|
||||||
Scenario: types.ScenarioExport,
|
Scenario: types.ScenarioExport,
|
||||||
|
Context: m.db.Statement.Context,
|
||||||
})
|
})
|
||||||
if searchSchemas, err = m.schemaLookup(childCtx, m.getDB(), domainName, m.naming.ModuleName, m.naming.TableName, types.ScenarioSearch); err != nil {
|
if searchSchemas, err = m.schemaLookup(childCtx, m.getDB(), domainName, m.naming.ModuleName, m.naming.TableName, types.ScenarioSearch); err != nil {
|
||||||
m.response.Failure(w, types.RequestRecordNotFound, "record not found", nil)
|
m.response.Failure(w, types.RequestRecordNotFound, "record not found", nil)
|
||||||
|
@ -1027,6 +1032,7 @@ func (m *Model) Import(w http.ResponseWriter, r *http.Request) {
|
||||||
TableName: m.naming.TableName,
|
TableName: m.naming.TableName,
|
||||||
Scenario: types.ScenarioImport,
|
Scenario: types.ScenarioImport,
|
||||||
Schemas: schemas,
|
Schemas: schemas,
|
||||||
|
Context: m.db.Statement.Context,
|
||||||
})
|
})
|
||||||
if r.Method == http.MethodGet {
|
if r.Method == http.MethodGet {
|
||||||
//下载导入模板
|
//下载导入模板
|
||||||
|
|
|
@ -206,6 +206,7 @@ type (
|
||||||
Schemas []*Schema //字段schema
|
Schemas []*Schema //字段schema
|
||||||
Request *http.Request //HTTP请求结构
|
Request *http.Request //HTTP请求结构
|
||||||
PrimaryKeyValue any //主键
|
PrimaryKeyValue any //主键
|
||||||
|
Context context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
ImportResult struct {
|
ImportResult struct {
|
||||||
|
|
Loading…
Reference in New Issue