當前位置: 首頁>>代碼示例>>Golang>>正文


Golang database.Database類代碼示例

本文整理匯總了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;未經允許,請勿轉載。