-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
refactor: Migrate FindOperator
SQL generation into QueryBuilder
#6797
refactor: Migrate FindOperator
SQL generation into QueryBuilder
#6797
Conversation
8c99a94
to
bfaa932
Compare
FindOperator
SQL calculation to QueryBuilderFindOperator
SQL generation into QueryBuilder
bfaa932
to
fb79ac0
Compare
FindOperator
SQL generation into QueryBuilderFindOperator
SQL generation into QueryBuilder
Looks good, thank you |
Hi there, The move to QueryBuilder make sense but the encapsulation has changed from public (in FindOperator) to protected (in QueryBuilder) locking the function to be no longer usable outside the QueryBuilder itself... Could you consider declaring computeFindOperatorExpression as public ? |
Hey there - while the Could you give examples of how you used this? I'd also suggest opening a new issue regarding that. |
@imnotjames Before opening an issue, I would like your input on this. This also broke my project where I have custom operators created: |
@stelescuraul I think that use case is closer to the exception than the norm - but a path forward would be good - totally get you there. We do already have an escape hatch in Might be worthwhile to extend
Or something like that? Either way, definitely open the issue. Would be good to continue the discussion there. |
same thing here, my ILike doesn't work. Could you fix that ASAP? |
we already have an |
Actually the part of my projet that use toSQL is a function witch automatically add conditions and joins to the where function of a QueryBuilder (or SelectQueryBuilder in my case). Here is a piece of code that use the toSQL() function in my projet: private addFiltersToQueryBuilder(queryBuilder: SelectQueryBuilder<any>, whereValue: FindOperator<any>) {
// ...
const whereCondition = [];
const whereConditionParams = {};
whereCondition.push(whereValue.toSql(this.connection, `${join.alias}.${whereKey}`, [`:${paramName}`]));
whereConditionParams[paramName] = whereValue.value;
const condition = whereCondition.join(' AND ');
queryBuilder.where(condition, whereConditionParams);
} That's was the only way I found in the TypeORM lib to correctly build conditions over predefined joins. Formerly I simply map an input object of filters coming from a GraphQL query into a QueryBuilder request.
Will create a QueryBuilder with where conditions and joins recursively. This way I can work with a kind of badass repository find() method :) |
That wasn't a supported API & the way you were using it is why I made it private - because it's likely going to change and break again in the future. Sorry that it stopped working for you. ): Off the top of my head, if you want to write something that builds your own queries in a way that we don't support, you can maintain a version of the translation separately, or use a more specialized library like knex, or you can always open a new issue for feature requests. |
Sorry, but i dont see So you made breaking change in a minor release. Do you have a "safe" branch/channel/etc without those? |
In a patch release, not a minor release.
|
@imnotjames thanks! |
Either way, I'm sorry that this change inadvertently caused issues with your code. We actually just merged in a change for
For the backport to bring |
This |
Migrate the code from
FindOperator.toSql
intoQueryBuilder.computeFindOperatorExpression
.The
QueryBuilder
is the de-facto location for all of the SQL Dialect generation.Let's move the
FindOperator.toSQL
to live there too.Effectively, we were passing a bunch of context from within the
QueryBuilder
back into theFindOperator
meaning we couldn't actually useFindOperator
withoutQueryBuilder
.The
FindOperator
had most of its code in a mechanism that wasn't even used by all drivers(eg, Mongo).
QueryBuilder
did not have encapsulation of the SQL dialect & more in-depth changesto the way we generate SQL based on the
FindOperator
can't be as easily done aswe didn't have context of the rest of the
QueryBuilder
.