Notice that user.id is used in the select of the limit subQuery in the working example. In the one that errors user.star() is used in the select of the limit subQuery.
Works
sql.define({name: 'user', columns: ['id','name','email', 'lastLogin']})
var limit = user.subQuery('limit-users').select(user.id)
limit.toString() // (SELECT "user".* FROM "user") "limit-users"
sql.select(limit.id, sql.constant(true).as("c")).from(limit).toString() // SELECT "limit-users"."id", TRUE AS "c" FROM (SELECT "user"."id" FROM "user") "limit-users"
Errors
sql.define({name: 'user', columns: ['id','name','email', 'lastLogin']})
var limit = user.subQuery('limit-users').select(user.star())
// ALSO results in error: var limit = user.subQuery('limit-users')
limit.toString() // (SELECT "user".* FROM "user") "limit-users"
sql.select(limit.id, sql.constant(true).as("c")).from(limit).toString()
AssertionError [ERR_ASSERTION]: Error while trying to add a non-existant node to a query
at constructor.Node.add (/lalitkapoor/pg-team/node_modules/sql/lib/node/index.js:17:3)
at constructor.Node.addAll (/lalitkapoor/pg-team/node_modules/sql/lib/node/index.js:78:10)
at constructor.select (/lalitkapoor/pg-team/node_modules/sql/lib/node/query.js:98:12)
at Sql.select (/lalitkapoor/pg-team/node_modules/sql/lib/index.js:51:16)
at repl:1:5
at ContextifyScript.Script.runInThisContext (vm.js:44:33)
at REPLServer.defaultEval (repl.js:239:29)
at bound (domain.js:301:14)
at REPLServer.runBound [as eval] (domain.js:314:12)
at REPLServer.onLine (repl.js:433:10)
Notice that
user.id
is used in the select of the limit subQuery in the working example. In the one that errorsuser.star()
is used in the select of the limit subQuery.Works
Errors