API page: https://api.drupal.org/api/drupal/core%21includes%21database.inc/group/d...
Enter a descriptive title (above) relating to Database abstraction layer, then describe the problem you have found:
On #2148255: [meta] Make better D8 api.d.o landing page, linked to high-level overview topics, and put it in Core api.php files we are making a better api.drupal.org landing page for Drupal 8. It needs to link to a page on the Database Abstraction Layer, and we already have such a page (see link above).
That page needs to describe PDO and entity field queries, in addition to what it currently covers. Perhaps it should be pared down into an overview with links to separate more detailed topics?
Comment | File | Size | Author |
---|---|---|---|
#8 | 2191445-query-docs-8.patch | 18.95 KB | jhodgdon |
#8 | interdiff.txt | 2.11 KB | jhodgdon |
#6 | interdiff.txt | 8.36 KB | jhodgdon |
#6 | 2191445-query-docs-6.patch | 19 KB | jhodgdon |
Comments
Comment #1
jhodgdonComment #2
jhodgdonI'm going to work on this one.
Comment #3
jhodgdonHere's a first pass on this documentation update.
As a note, I also filed:
#2287151: StatementInterface docs have a bunch of obsolete stuff in them
and anyone reviewing this patch might want to take a look at that too?
Comment #4
jhodgdonchx made some suggestions in IRC. New patch.
Comment #5
Crell CreditAttribution: Crell commentedI question if this belongs in the database documentation. It's part of the entity system, NOT the Database component. The database component should be seen as a stand-alone library; there's only a few technical reasons it isn't yet, because we've not fully unwound it. Assume that DBTNG will eventually move to \Drupal\Component\ and potentially even its own repository.
A warning to not use the DB API directly for querying entities is fine, but the actual documentation of how to do so belongs elsewhere.
Except most of the time you should get the entity.query service injected rather than accessing the container directly or calling the global. (This is a global problem of how to document things, not specific to this case.)
If we're updating the documentation, we should also not refer to deprecated wrapper functions and use the object form instead.
JOINs are fairly safe in most cases. If you can get away with just using query() you should.
Perhaps it's time to start using the short-array syntax here, as it's actually considerably more readable. (Fewer things using (), so the code looks less like LISP.)
"So" is unnecessary in this sentence.
As above, we should stop referring to the functions and use the methods instead.
We're likely to remove the transparent fallback logic, as it's kinda broken right now: #2278971: Deprecate Connection::supportsTransactions()
Comment #6
jhodgdonThanks for the review! I've made some updates... moved the entity stuff into the entity topic, and addressed most of your points (I think).
A few notes:
The functions db_select() and friends are *not* deprecated and are used quite extensively in Core. I did already have a section at the end about the connection objects... I've put in more references to that section. But I don't want to rewrite the entire topic and its examples. I don't think it adds a lot.
Regarding the transaction code... that was already in the topic, and I only cleaned up the wording a bit... I really don't know anything much about transactions. If that other patch lands, it should be updating the documentation, correct? We need to document what's true now, not wait for some other issue to maybe be resolved.
Regarding #5, I have no idea what you mean by "short array syntax", sorry.
Note: The interdiff here is almost as big as the patch; you may have better luck just reviewing the new patch.
Comment #7
chx CreditAttribution: chx commented+ * In this context, "simple" means a query that does not involve a LIKE
+ * or any SQL functions.
* For SELECT queries involving LIKE, joins, or any SQL functions, instead of
* using the db_query() and db_query_range() functions,
Complicated. What DBTNG does, if your conditions has a single operator
->condition('d.data', "% $key %", 'LIKE')
then yes DBTNG can and will map your LIKE per database driver. However when using functions in the select partdb_query('SELECT CONCAT(:a1, CONCAT(name, CONCAT(:a2, CONCAT(age, :a3)))) FROM {test} WHERE age = :age',
then that's fine.JOINs are very fine in a db_query().
When you absolutely must use the query builder is when the query string (without arguments) is not a fixed string; when the query string itself is dynamic. That immediately mandates db_select because otherwise you will create a sechole (even core did have a weakness relating to that although not an outright sechole).
I hope this explains it; sorry for not being able to put it into succint words. I would be glad helping in wordsmithing this. And yes, this is in the current docs and yes the current docs is incorrect.
Comment #8
jhodgdonGood feedback, thanks! Here's a new patch.
Comment #9
chx CreditAttribution: chx commentedLet's do this, we can bikeshed more later.
Comment #10
webchickCommitted and pushed to 8.x. Thanks!