(ctx Context, m *qcode.Mutate, qc *qcode.QCode, varName string, renderFilter func())
| 931 | } |
| 932 | |
| 933 | func (d *SQLiteDialect) RenderLinearConnect(ctx Context, m *qcode.Mutate, qc *qcode.QCode, varName string, renderFilter func()) { |
| 934 | // Step 1: SELECT to capture IDs matching the filter |
| 935 | ctx.WriteString(`SELECT json_object('id', `) |
| 936 | renderPKIDExpr(ctx, m) |
| 937 | ctx.WriteString(`)`) |
| 938 | |
| 939 | if m.IsJSON { |
| 940 | ctx.WriteString(` FROM `) |
| 941 | d.RenderLinearValues(ctx, m, func() { |
| 942 | ctx.AddParam(Param{Name: qc.ActionVar, Type: "json"}) |
| 943 | }) |
| 944 | ctx.WriteString(`, `) |
| 945 | } else { |
| 946 | ctx.WriteString(` FROM `) |
| 947 | } |
| 948 | ctx.Quote(m.Ti.Name) |
| 949 | |
| 950 | ctx.WriteString(` WHERE `) |
| 951 | renderFilter() |
| 952 | |
| 953 | ctx.WriteString(" -- @gj_ids=") |
| 954 | ctx.WriteString(varName) |
| 955 | ctx.WriteString("\n; ") |
| 956 | |
| 957 | // Step 2: Determine relationship direction and perform appropriate UPDATE |
| 958 | // For recursive self-referential tables (e.g., comments.reply_to_id -> comments.id), |
| 959 | // we need to update the CONNECTED row's FK to point to the PARENT. |
| 960 | |
| 961 | // Check if this is a recursive relationship (same table on both sides) |
| 962 | isRecursive := m.Rel.Left.Col.Table == m.Rel.Right.Col.Table |
| 963 | |
| 964 | // Find the parent mutation this connect depends on |
| 965 | var parentVar string |
| 966 | var parentMut *qcode.Mutate |
| 967 | for id := range m.DependsOn { |
| 968 | pm := qc.Mutates[id] |
| 969 | parentVar = d.getVarName(pm) |
| 970 | parentMut = &pm |
| 971 | break |
| 972 | } |
| 973 | |
| 974 | if parentVar == "" || parentMut == nil { |
| 975 | return |
| 976 | } |
| 977 | |
| 978 | if isRecursive { |
| 979 | // For recursive relationships (e.g., comments -> comments via reply_to_id): |
| 980 | // The FK column is on the same table. We need to determine which column is the FK. |
| 981 | // The non-PK column in the relationship is the FK. |
| 982 | var fkColName string |
| 983 | if !m.Rel.Left.Col.PrimaryKey { |
| 984 | fkColName = m.Rel.Left.Col.Name |
| 985 | } else if !m.Rel.Right.Col.PrimaryKey { |
| 986 | fkColName = m.Rel.Right.Col.Name |
| 987 | } |
| 988 | |
| 989 | if fkColName != "" { |
| 990 | // UPDATE the connected (child) row's FK to point to the parent |
nothing calls this directly
no test coverage detected