uptrace / bun

SQL-first Golang ORM
https://bun.uptrace.dev
BSD 2-Clause "Simplified" License
3.46k stars 206 forks source link

feat: apply ModelTableExpr for SELECT query #975

Open JunNishimura opened 3 months ago

JunNishimura commented 3 months ago

Overview

This PR fixes #968.

The ModelTableExpr method in the existing implementation simply overwrites the table name in the FROM clause, but not the table name used as the column name prefix in the SELECT clause (such as SELECT users.name). Therefore, the Insert, Update, and Delete processes were fine, but the Select process was not working as expected.

What's changed

1. add Table Parser

Extract table names and aliases from queries passed as arguments to ModelTableExpr method.

2. Update columns builder of select query

Consider the table name specified in ModelTableExpr when constructing columns in the SELECT clause.