Comments (18)
The count() method only takes the where
clause instead of the filter
. Your REST URL should be:
http://localhost:3000/api/malts/count?where[maltName][like]=%25ap%25
from loopback-connector-mysql.
+1 this needs better documentation
from loopback-connector-mysql.
+1 to needing this better documented
from loopback-connector-mysql.
The count() method only takes the
where
clause instead of thefilter
. Your REST URL should be:http://localhost:3000/api/malts/count?where[maltName][like]=%25ap%25
I don't know how to count with two filters, it works only with one, can you help me please?
I try with that:
http://localhost:3000/Users/count?where[profileC][ilike]=%25Designer%25[additionalSkillsC][ilike]=%25figma%25
from loopback-connector-mysql.
This is being fixed by #32.
from loopback-connector-mysql.
Fixed by [email protected]
from loopback-connector-mysql.
Unfortunately, this is not fixed neither v1.2.3 nor v1.3.0.
from loopback-connector-mysql.
How did you call the count()? The 1st arg should be an object for filter.where, see:
https://github.com/strongloop/loopback-connector-mysql/blob/master/test/mysql.test.js#L299
from loopback-connector-mysql.
I call it thru REST API. I do it on a listing page, and after having called find(), I call count() with the same filter settings to create a pagination control:
The resulting SQL statements on the database:
SELECT malt_key
, malt_name
FROM malt
WHERE malt_name
LIKE '%ap%' ORDER BY malt_name
ASC LIMIT 10
SELECT count(*) as cnt FROM malt
The last one sould be the following:
SELECT count(*) as cnt FROM malt
WHERE malt_name
LIKE '%ap%'
The fields, order, limit and skip arguments are ignored, that is right.
*** It would be a nice feature if find() would have an includeTotalCount Boolean argument, and it optionally would return the total item count using the filter settings.
from loopback-connector-mysql.
O.K. This way it works in deed. However, the documentation is rather gappy, and sometimes confusing. E.g. in Model REST API, at Find first instance section it says the argument is filter. On the other hand, in LoopBack reference, DataModel class, at findOne() it says the params is a where object.
from loopback-connector-mysql.
@marmarosi @jamesw6811 Please create a new issue with specifics (ie. why the docs are bad, what do you need to see, which parts need improvement, etc) so that we can get it assigned to @crandmck to get it fixed. We do not take action on comments in closed issues.
from loopback-connector-mysql.
The count() method only takes the where clause instead of the filter
@raymondfeng We should probably add an alias functions that take a filter and do the same thing. Probably something to add for my LB3 juggler proposal.
from loopback-connector-mysql.
Hey @cfjedimaster I tried to clarify Where clause for queries and Where clause for other methods about the where clause for count()
. LMK if it can be clarified further or somewhere else.
from loopback-connector-mysql.
@crandmck The where
object is the same for all methods. What's different is that some methods (such as count) take a where
object directly while others (such as find) take a filter
that can contain where
. The filter
object also supports other child items such as limit
and order
.
from loopback-connector-mysql.
OK, but we went through this whole fire-drill some time ago to describe the difference in the syntax (which we document and give examples of) because sometimes the where clause is wrapped in {where: ... }
and sometimes not.
The docs say:
For query methods such as find(), findOrCreate(), or findOne(), use
{where: {property: value}}
and
... for methods that update and delete (and count()), don't wrap the where clause in a
{ where : ... }
, ... so use{property: value}
I just tested that myself and it seems to be accurate.
I think perhaps it amounts to the same thing, but we're saying it in different ways. Perhaps your way of describing it makes more sense...?
from loopback-connector-mysql.
You are right. The key is that find/findOne takes a filter object while count/deleteAll/updateAll takes a where object.
from loopback-connector-mysql.
It kinda makes sense now - to be honest, I probably would have stopped reading before "Where clause for other methods". Honestly, it seems weird and arbitrary a bit as well - but I'm still new to LB.
One suggestion. The first doc section includes REST API examples, the second does. It should, shouldn't it?
from loopback-connector-mysql.
The count() method only takes the
where
clause instead of thefilter
. Your REST URL should be:
http://localhost:3000/api/malts/count?where[maltName][like]=%25ap%25I don't know how to count with two filters, it works only with one, can you help me please?
I try with that:
http://localhost:3000/Users/count?where[profileC][ilike]=%25Designer%25[additionalSkillsC][ilike]=%25figma%25
Hello dear,
I was in the same case as you.
To apply multiple filters just add a "and" property with an array of your "conditions"
{
"or":[
{
"statusId":"5"
},
{
"statusId":"6"
},
{
"statusId":"7"
}
]
}
from loopback-connector-mysql.
Related Issues (20)
- Tests are failing HOT 3
- Default Function UUID inconsistence HOT 1
- Connection to database hangs after Error: read ETIMEDOUT HOT 2
- Model's ID not set as private key in MySQL database
- RAW Query fails when server and DB are on differents IPs
- Fulltext index on a model property is not migrated to the datasource
- mysql.index is not work on property
- compatibility issue with mysql aurora 8.0.* using regex HOT 1
- n-gram specification on FULLTEXT index HOT 2
- Mapping of type blob/longblob to Binary fails the lb4 discover command HOT 1
- Fix CI pipeline HOT 1
- FULLTEXT | MYSQL | failed with status code 500. Error: ER_PARSE_ERROR: You have an error in your SQL syntax; HOT 1
- Add support for nodejs v18 and mysql v8 HOT 5
- Empty body on update generates an MySQL error HOT 2
- Support Latest Node 18 (LTS) HOT 1
- Dependency Dashboard
- Remove unknown options to the mysql2 initalizer HOT 3
- empty string is converted to empty object in LoopBack3
- getContext() gets lost when switching from mysql to mysql2
- In loopback 4, Hasmany relation returns undefined instead of empty array when there is no related data
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from loopback-connector-mysql.