package eg;

import static org.seamframework.sql.Type.VARCHAR;

import org.seamframework.sql.Expression;
import org.seamframework.sql.From;
import org.seamframework.sql.Join;
import org.seamframework.sql.Parameter;
import org.seamframework.sql.Query;

import eg.Schema.permissions;
import eg.Schema.users;

class LoginQuery extends Query {
	
	From<users> user = from(users.table, "u");
	Join<permissions> permission = user.join(permissions.table, "p");
	{
		permission.on( eq( user.get(users.username), 
				permission.get(permissions.username) ) );
	}
	
	Expression<String> name = user.get(users.name);
	Expression<Short> age = user.get(users.age);
	Expression<String> permissionId = permission.get(permissions.id);
	
	Parameter<String> username = parameter(VARCHAR);
	Parameter<String> password = parameter(VARCHAR);
	
	{
		select(name, age, permissionId);
		where( and( eq( user.get(users.username), username ), 
				eq( user.get(users.password), password ) ) );
		orderBy(permissionId);
	}
	
}