本文整理汇总了Golang中database.Database类的典型用法代码示例。如果您正苦于以下问题:Golang Database类的具体用法?Golang Database怎么用?Golang Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Database类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: FK
// Makes a foreign key constraint on a column, together with delete/update restricted triggers.
func FK(db *database.Database, fkTable *table.Table, fkColumn string, pkTable *table.Table, pkColumn string) int {
/*
In fact, the "pkColumn" in "pkTable" does not have to have PK constraint.
FK constraint will still function properly in that case.
*/
beforeTable, status := db.Get("~before")
if status != st.OK {
return status
}
// On FK table and FK column, triggers FK function before insert.
status = beforeTable.Insert(map[string]string{"TABLE": fkTable.Name, "COLUMN": fkColumn, "FUNC": "FK", "OP": "IN", "PARAM": pkTable.Name + ";" + pkColumn})
if status != st.OK {
return status
}
// On FK table and FK column, triggers FK function before update.
status = beforeTable.Insert(map[string]string{"TABLE": fkTable.Name, "COLUMN": fkColumn, "FUNC": "FK", "OP": "UP", "PARAM": pkTable.Name + ";" + pkColumn})
if status != st.OK {
return status
}
// On PK table and PK column, triggers UR (update restricted) function before update.
status = beforeTable.Insert(map[string]string{"TABLE": pkTable.Name, "COLUMN": pkColumn, "FUNC": "UR", "OP": "UP", "PARAM": fkTable.Name + ";" + fkColumn})
if status != st.OK {
return status
}
// On PK table and PK column, triggers DR (delete restricted) function before delete.
status = beforeTable.Insert(map[string]string{"TABLE": pkTable.Name, "COLUMN": pkColumn, "FUNC": "DR", "OP": "DE", "PARAM": fkTable.Name + ";" + fkColumn})
return beforeTable.Flush()
}
开发者ID:postfix,项目名称:DBGo,代码行数:29,代码来源:triggermaker.go
示例2: RemoveFK
// Removes foreign key constraint from a column, together with delete/update restricted triggers.
func RemoveFK(db *database.Database, fkTable *table.Table, fkColumn string, pkTable *table.Table, pkColumn string) int {
beforeTable, status := db.Get("~before")
if status != st.OK {
return status
}
query := ra.New()
query.Load(beforeTable)
// Remove FK constraint on FK column.
status = findAndDelete(beforeTable, query,
ra.Condition{Alias: "TABLE", Filter: filter.Eq{}, Parameter: fkTable.Name},
ra.Condition{Alias: "COLUMN", Filter: filter.Eq{}, Parameter: fkColumn},
ra.Condition{Alias: "FUNC", Filter: filter.Eq{}, Parameter: "FK"},
ra.Condition{Alias: "PARAM", Filter: filter.Eq{}, Parameter: pkTable.Name + ";" + pkColumn})
if status != st.OK {
return status
}
// Remove delete restricted trigger.
status = findAndDelete(beforeTable, query,
ra.Condition{Alias: "TABLE", Filter: filter.Eq{}, Parameter: pkTable.Name},
ra.Condition{Alias: "COLUMN", Filter: filter.Eq{}, Parameter: pkColumn},
ra.Condition{Alias: "FUNC", Filter: filter.Eq{}, Parameter: "DR"},
ra.Condition{Alias: "PARAM", Filter: filter.Eq{}, Parameter: fkTable.Name + ";" + fkColumn})
if status != st.OK {
return status
}
// Remove update restricted trigger.
return findAndDelete(beforeTable, query,
ra.Condition{Alias: "TABLE", Filter: filter.Eq{}, Parameter: pkTable.Name},
ra.Condition{Alias: "COLUMN", Filter: filter.Eq{}, Parameter: pkColumn},
ra.Condition{Alias: "FUNC", Filter: filter.Eq{}, Parameter: "UR"},
ra.Condition{Alias: "PARAM", Filter: filter.Eq{}, Parameter: fkTable.Name + ";" + fkColumn})
}
开发者ID:postfix,项目名称:DBGo,代码行数:33,代码来源:triggermaker.go
示例3: RemovePK
// Removes primary key constraint from a column.
func RemovePK(db *database.Database, t *table.Table, name string) int {
beforeTable, status := db.Get("~before")
if status != st.OK {
return status
}
query := ra.New()
query.Load(beforeTable)
return findAndDelete(beforeTable, query,
ra.Condition{Alias: "TABLE", Filter: filter.Eq{}, Parameter: t.Name},
ra.Condition{Alias: "COLUMN", Filter: filter.Eq{}, Parameter: name},
ra.Condition{Alias: "FUNC", Filter: filter.Eq{}, Parameter: "PK"})
}
开发者ID:postfix,项目名称:DBGo,代码行数:13,代码来源:triggermaker.go
示例4: Execute
func (dr DR) Execute(db *database.Database, t *table.Table, column string, extraParameters []string, row1, row2 map[string]string) int {
// extraParameters is FK table name[0] and FK column name[1]
fkTable, status := db.Get(extraParameters[0])
if status != st.OK {
return status
}
found, status := find(extraParameters[1], row1[column], fkTable)
if found && status == st.OK {
return st.DeleteRestricted
}
return status
}
开发者ID:postfix,项目名称:DBGo,代码行数:12,代码来源:constraint.go
示例5: PK
// Makes a primary key constraint on a column.
func PK(db *database.Database, t *table.Table, name string) int {
beforeTable, status := db.Get("~before")
if status != st.OK {
return status
}
// On PK table and PK column, triggers PK function before insert.
status = beforeTable.Insert(map[string]string{"TABLE": t.Name, "COLUMN": name, "FUNC": "PK", "OP": "IN"})
if status != st.OK {
return status
}
// On PK table and PK column, triggers PK function before update.
status = beforeTable.Insert(map[string]string{"TABLE": t.Name, "COLUMN": name, "FUNC": "PK", "OP": "UP"})
if status != st.OK {
return status
}
return beforeTable.Flush()
}
开发者ID:postfix,项目名称:DBGo,代码行数:18,代码来源:triggermaker.go
注:本文中的database.Database类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论