How would I write this query in object script rather than SQL?
Query GetSessionIdByUserName(UserName As %String) As %SQLQuery [ Private ]
{
SELECT %ID from Sample.Session
WHERE UserName = :UserName
}
All I seem to find so far in the documentation is %OpenId
##class(Sample.Session).%OpenId(id)
What happens when the id is not known and needs to be found first?
There aren't built in methods to do something like get the session ID by user name. You need to write them yourself, and SQL is probably usually the best way to do it. You can wrap the SQL in a method though, rather than a query.