squirrel icon indicating copy to clipboard operation
squirrel copied to clipboard

JoinSelect feature for joining a SelectBuilder

Open jzbyers opened this issue 5 years ago • 2 comments

This would allow us to join against a subquery against another table with conditional where clauses. Otherwise, we need to join against the entire table, which does not satisfy our performance requirements.

jzbyers avatar Mar 26 '20 21:03 jzbyers

I was able to work around this with the current interface using the JoinClause you can pass it a sqlizer, it looks something like this

squirrel.Select("resources.*").
	From("resources").
	JoinClause(
		// join for permission checks
		squirrel.Select("resource_id::uuid", "array_agg(action) AS actions").
			From("resource_entities").
			Where(squirel.Eq{"user_id": userID}).
			GroupBy("resource_id").
			Prefix("LEFT JOIN (").Suffix(") AS ra ON (resources.resource_id = ra.resource_id)"),
	).
	Where(filterSqlizer)

LucasRoesler avatar May 09 '20 08:05 LucasRoesler

That is an ok workaround, but I would really like to see JoinSelect, as it would be significantly cleaner and not require use of Prefix and Suffix

veqryn avatar Apr 05 '21 21:04 veqryn