Skip to content

can it support set alias? #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fashen007 opened this issue Apr 11, 2021 · 1 comment
Closed

can it support set alias? #62

fashen007 opened this issue Apr 11, 2021 · 1 comment
Labels

Comments

@fashen007
Copy link

fashen007 commented Apr 11, 2021

for example

var userId = 1;
var columns = ['username AS 用户名', 'email AS 邮箱'];
var sql     = SqlString.format('SELECT ?? FROM ?? WHERE id = ?', [columns, 'users', userId]);

How to make this work correctly?

@dougwilson
Copy link
Member

dougwilson commented Sep 15, 2021

You would use the toSqlString functionality to create column objects. There are many ways to do this, but here is one:

function Column(name, alias) {
  return SqlString.raw(SqlString.format('?? AS ??', [name, (alias || name)]))
}
var userId = 1;
var columns = [Column('username', '用户名'), Column('email', '邮箱')];
var sql     = SqlString.format('SELECT ? FROM ?? WHERE id = ?', [columns, 'users', userId]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants