// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.27.0
// source: query.sql

package querytest

import (
	"context"
)

const getLatestVersionWithSubquery = `-- name: GetLatestVersionWithSubquery :one
SELECT * 
FROM versions
WHERE versions.id IN (
  WITH RECURSIVE search_tree(id) AS (
	SELECT id, 0 as chain_id, 0 as chain_counter
    FROM versions
  )
  SELECT DISTINCT ON (search_tree.chain_id) 
	search_tree.id
  FROM search_tree   
  ORDER BY search_tree.chain_id, chain_counter DESC
)
`

func (q *Queries) GetLatestVersionWithSubquery(ctx context.Context) (Version, error) {
	row := q.db.QueryRow(ctx, getLatestVersionWithSubquery)
	var i Version
	err := row.Scan(&i.ID, &i.Name, &i.PreviousVersionID)
	return i, err
}
