Пример #1
0
// roleExists returns if a role exists or not.
func roleExists(c *spiffy.DbConnection, tx *sql.Tx, roleName string) (bool, error) {
	return c.QueryInTx(`SELECT 1 FROM pg_roles WHERE rolname ilike $1`, tx, roleName).Any()
}
Пример #2
0
// IndexExists returns if a index exists on a table on the given connection.
func indexExists(c *spiffy.DbConnection, tx *sql.Tx, tableName, indexName string) (bool, error) {
	return c.QueryInTx(`SELECT 1 FROM pg_catalog.pg_index ix join pg_catalog.pg_class t on t.oid = ix.indrelid join pg_catalog.pg_class i on i.oid = ix.indexrelid WHERE t.relname = $1 and i.relname = $2 and t.relkind = 'r'`, tx, strings.ToLower(tableName), strings.ToLower(indexName)).Any()
}
Пример #3
0
// ColumnExists returns if a column exists on a table on the given connection.
func columnExists(c *spiffy.DbConnection, tx *sql.Tx, tableName, columnName string) (bool, error) {
	return c.QueryInTx(`SELECT 1 FROM information_schema.columns i WHERE i.table_name = $1 and i.column_name = $2`, tx, strings.ToLower(tableName), strings.ToLower(columnName)).Any()
}
Пример #4
0
// ConstraintExists returns if a constraint exists on a table on the given connection.
func constraintExists(c *spiffy.DbConnection, tx *sql.Tx, constraintName string) (bool, error) {
	return c.QueryInTx(`SELECT 1 FROM pg_constraint WHERE conname = $1`, tx, strings.ToLower(constraintName)).Any()
}
Пример #5
0
// TableExists returns if a table exists on the given connection.
func tableExists(c *spiffy.DbConnection, tx *sql.Tx, tableName string) (bool, error) {
	return c.QueryInTx(`SELECT 1 FROM pg_catalog.pg_tables WHERE tablename = $1`, tx, strings.ToLower(tableName)).Any()
}