Add support for Postgres LATERAL joins #2268

Open
opened 2023-05-25 01:57:45 +00:00 by segfault · 1 comment

I think all that would be needed would be another function that appends the string after JOIN. It seems like it might be somewhat easy to do.I would put up a PR but I’m not sure I know enough and would probably miss stuff.

count, err := sesh.Table("integration_config").Alias("ic").
		Select(`
			ic.id																	AS id
			,ic.organization_id														AS organization_id
			,ic.integration_type_id													AS integration_type_id
			,ic.config																AS config
			,it.name 																AS type_name
			,ic.created_at															AS created_at
			,ic.updated_at															AS updated_at
		`).
		Join("LEFT", []string{"integration_type", "it"}, "it.id = ic.integration_type_id").
		Join("LEFT",
			[]string{`
			LATERAL (
				SELECT
					icl.integration_config_id
					,icl.location_id
					,icl.is_enabled
					,icl.created_at
					,icl.updated_at
				FROM
					integration_config_locations AS icl
				WHERE icl.integration_config_id = ic.id
			)`, "jicl",
			}, "jicl.integration_config_id = ic.id").
		FindAndCount(&recs)
I think all that would be needed would be another function that appends the string after `JOIN`. It seems like it might be somewhat easy to do.I would put up a PR but I’m not sure I know enough and would probably miss stuff. ``` count, err := sesh.Table("integration_config").Alias("ic"). Select(` ic.id AS id ,ic.organization_id AS organization_id ,ic.integration_type_id AS integration_type_id ,ic.config AS config ,it.name AS type_name ,ic.created_at AS created_at ,ic.updated_at AS updated_at `). Join("LEFT", []string{"integration_type", "it"}, "it.id = ic.integration_type_id"). Join("LEFT", []string{` LATERAL ( SELECT icl.integration_config_id ,icl.location_id ,icl.is_enabled ,icl.created_at ,icl.updated_at FROM integration_config_locations AS icl WHERE icl.integration_config_id = ic.id )`, "jicl", }, "jicl.integration_config_id = ic.id"). FindAndCount(&recs) ```
Owner

Does this work? What's the problem?

Does this work? What's the problem?
lunny added the
need
feedback
label 2023-07-23 03:06:43 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#2268
No description provided.