WIP: Refactor parse

This commit is contained in:
2026-06-05 15:54:47 +02:00
parent d20184a6f0
commit 146f07fa02
10 changed files with 255 additions and 180 deletions
+16 -2
View File
@@ -17,7 +17,7 @@ type Select[T any] struct {
args []any
limit int64
offset int64
ordering []OrderBy
ordering []schema.OrderBy
results []T
}
@@ -55,7 +55,7 @@ func (s *Select[T]) Offset(offset int64) *Select[T] {
// Sets the order by part of the select query
// Returns the pointer of the Select instance
func (s *Select[T]) OrderBy(ordering ...OrderBy) *Select[T] {
func (s *Select[T]) OrderBy(ordering ...schema.OrderBy) *Select[T] {
s.ordering = ordering
return s
}
@@ -65,10 +65,15 @@ func (s *Select[T]) Results() []T {
return s.results
}
// Executes the select query based on the Select exec instance
// Returns an error if theres any
func (s *Select[T]) Execute(conn *simpleorm.DBConnection) error {
return s.execute(conn, nil)
}
// Executes the select query based on the Select exec instance
// If tx is given, the transaction is used instead of the conn
// Returns an error if theres any
func (s *Select[T]) execute(conn *simpleorm.DBConnection, tx *sql.Tx) error {
// Reinit the results, new execution
s.results = []T{}
@@ -92,6 +97,15 @@ func (s *Select[T]) execute(conn *simpleorm.DBConnection, tx *sql.Tx) error {
effectiveArgs = append(effectiveArgs, s.offset)
}
if len(s.ordering) > 0 {
dml += " ORDER BY"
for _, orderBy := range s.ordering {
dml += " " + orderBy.Field + " " + orderBy.Direction
}
}
log.LogInfo("Preparing sql: %s", dml)
log.LogDebug("Preparing sql: %s, with args: %s", dml, effectiveArgs)
var stmt *sql.Stmt