本文整理匯總了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()
}
示例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})
}
示例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"})
}
示例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
}
示例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()
}