Commit Graph

55 Commits

Author SHA1 Message Date
Mike Bayer 2bcc97da42 implement batched INSERT..VALUES () () for executemany
the feature is enabled for all built in backends
when RETURNING is used,
except for Oracle that doesn't need it,  and on
psycopg2 and mssql+pyodbc it is used for all INSERT statements,
not just those that use RETURNING.

third party dialects would need to opt in to the new feature
by setting use_insertmanyvalues to True.

Also adds dialect-level guards against using returning
with executemany where we dont have an implementation to
suit it.   execute single w/ returning still defers to the
server without us checking.

Fixes: #6047
Fixes: #7907
Change-Id: I3936d3c00003f02e322f2e43fb949d0e6e568304
2022-09-24 11:15:32 -04:00
Mike Bayer f0bcd57f9e remove obtuse section about "bundled bind parameters"
Just looking for basics on insert in the first pages
of the tutorial I see this weird detour into something that
nobody ever uses and definitely isn't going to make sense
to the people I see complaining about our docs on twitter,
remove this.   the tutorial probably needs a big sweep
for wordy obtuse things.  the userbase is changing and
we really have a lot of brand-new-to-programming types coming
in.

Change-Id: I3bb11f0399e55edbb8f874e7eb63c40616b04e8b
2022-09-17 10:18:56 -04:00
Mike Bayer cc72081b0c add docs for session.get()
also use the term "primary key" a bit more

Change-Id: Ib654b30a9d06a2aeed019b4754db920afe05d774
References: https://twitter.com/encthenet/status/1567644850471989248
2022-09-07 19:00:31 -04:00
Mike Bayer 1ecbf14cc2 implement tuple-slices from .c collections
Added new syntax to the ``.c`` collection on all :class:`.FromClause`
objects allowing tuples of keys to be passed to ``__getitem__()``, along
with support for ``select()`` handling of ``.c`` collections directly,
allowing the syntax ``select(table.c['a', 'b', 'c'])`` to be possible. The
sub-collection returned is itself a :class:`.ColumnCollection` which is
also directly consumable by :func:`_sql.select` and similar now.

Fixes: #8285
Change-Id: I2236662c477ffc50af079310589e213323c960d1
2022-08-01 21:46:33 +00:00
Mike Bayer 9a37ebdf99 update ORM declarative docs for new features
I screwed up a rebase or something so this was
temporarily in Ic51a12de3358f3a451bd7cf3542b375569499fc1

Change-Id: I847ee1336381221c0112b67854df022edf596b25
2022-07-16 16:28:11 -04:00
Jefferson Oliveira 52317cec36 fix documentation typo 2022-06-29 11:53:36 -03:00
Mike Bayer c7519e94b5 sub-categorize special function forms
this is the tutorial, which should have some semblence of
not getting too far into the weeds.  however, as we dont
really have other places to explain SQL concepts, and SQL
functions have a lot of them, we dont have another home right
now.  so at least further sub-categorize window functions,
table/column valued functions, and WITHIN GROUP into an
"advanced function techniques" section with a disclaimer that
these are less common use cases.

Change-Id: I4b16bd5673c0bd39a9b880338f6ce3cfbafbe271
2022-06-22 18:50:35 -04:00
Federico Caselli db08a69948 rearchitect reflection for batched performance
Rearchitected the schema reflection API to allow some dialects to make use
of high performing batch queries to reflect the schemas of many tables at
once using much fewer queries. The new performance features are targeted
first at the PostgreSQL and Oracle backends, and may be applied to any
dialect that makes use of SELECT queries against system catalog tables to
reflect tables (currently this omits the MySQL and SQLite dialects which
instead make use of parsing the "CREATE TABLE" statement, however these
dialects do not have a pre-existing performance issue with reflection. MS
SQL Server is still a TODO).

The new API is backwards compatible with the previous system, and should
require no changes to third party dialects to retain compatibility;
third party dialects can also opt into the new system by implementing
batched queries for schema reflection.

Along with this change is an updated reflection API that is fully
:pep:`484` typed, features many new methods and some changes.

Fixes: #4379
Change-Id: I897ec09843543aa7012bcdce758792ed3d415d08
2022-06-18 14:57:26 -04:00
Mike Bayer 1c99edf1b9 migrate labels to new tutorial
other org changes and some sections from old tutorial
ported to new tutorial.

Change-Id: Ic0fba60ec82fff481890887beef9ed0fa271875a
2022-06-07 12:25:19 -04:00
Robert Kulagowski b66d57451a Update dbapi_transactions.rst (#8032)
If you're defining 'y=row.y' then you might as well use 'y' in the print statement.
2022-05-18 22:25:18 +02:00
Mike Bayer 5e88e6e89a fix most sphinx warnings (1.4)
still can't figure out the warnings with some of the older
changelog files.

this cherry-picks the sphinx fixes from 1.4 and additionally
fixes a small number of new issues in the 2.0 docs. However,
2.0 has many more errors to fix, primarily from the removal
of the legacy tutorials left behind a lot of labels that need
to be re-linked to the new tutorial.

Fixes: #7946
Change-Id: Id657ab23008eed0b133fed65b2f9ea75a626215c
(cherry picked from commit 9b55a42345)
2022-05-16 11:21:36 -04:00
Mike Bayer cd628fad7c more expire_on_commit reminders
the session commit/close docs still feel awkward in how
one learns about this operation.   hopefully another pass
over 2.0 can make things more linear.

removed a 1.4 note about autobegin that was completely inaccurate;
commit() does autobegin so it has an effect, just not usually
on the database.

Change-Id: Iaa4b96bd3df6cf82e851b2943322ddad7abbbac0
2022-05-13 10:25:37 -04:00
Mike Bayer 1dffb7cede clarify alternative mapping example
this second example is not part of the doctest steps,
clarify that it's not part of code examples to be present
in execution steps.   Add an extra registry +
declarative base on top
so that even if someone does run it, the Base will have
been reset and the examples will continue to work
(noting that column order in statements may change, but
probably nothing else).

Fixes: #7891
Change-Id: Icb1ba310230841e502185d9d0cadd3c18d467292
2022-04-03 10:52:30 -04:00
Maple 2ea12b2f5c fix small indentation typo (#7882) 2022-04-03 11:30:08 +02:00
Mike Bayer 86fbd4a215 ORM quickstart
This is done in 1.4 style so it can be backported to 1.4.
Will put this up as is, we can work on it.   For 2.0, the
ORM mapping will be updated to mapped_column() style when
we do the full pass.

Change-Id: Icfdf81449973844dac244b3a107ce955a7d3b16c
2022-03-11 11:28:26 -05:00
Mike Bayer a4bb502cf9 pep-484 for engine
All modules in sqlalchemy.engine are strictly
typed with the exception of cursor, default, and
reflection.  cursor and default pass with non-strict
typing, reflection is waiting on the multi-reflection
refactor.

Behavioral changes:

* create_connect_args() methods return a tuple of list,
  dict, rather than a list of list, dict
* removed allow_chars parameter from
  pyodbc connector ._get_server_version_info()
  method
* the parameter list passed to do_executemany is now
  a list in all cases. previously, this was being run
  through dialect.execute_sequence_format, which
  defaults to tuple and was only intended for individual
  tuple params.
* broke up dialect.dbapi into dialect.import_dbapi
  class method and dialect.dbapi module object.  added
  a deprecation path for legacy dialects.  it's not
  really feasible to type a single attr as a classmethod
  vs. module type.  The "type_compiler" attribute also
  has this problem with greater ability to work around,
  left that one for now.
* lots of constants changing to be Enum, so that we can
  type them.  for fixed tuple-position constants in
  cursor.py / compiler.py (which are used to avoid the
  speed overhead of namedtuple), using Literal[value]
  which seems to work well
* some tightening up in Row regarding __getitem__, which
  we can do since we are on full 2.0 style result use
* altered the set_connection_execution_options and
  set_engine_execution_options event flows so that the
  dictionary of options may be mutated within the event
  hook, where it will then take effect as the actual
  options used.  Previously, changing the dict would
  be silently ignored which seems counter-intuitive
  and not very useful.
* A lot of DefaultDialect/DefaultExecutionContext
  methods and attributes, including underscored ones, move
  to interfaces.  This is not fully ideal as it means
  the Dialect/ExecutionContext interfaces aren't publicly
  subclassable directly, but their current purpose
  is more of documentation for dialect authors who should
  (and certainly are) still be subclassing the DefaultXYZ
  versions in all cases

Overall, Result was the most extremely difficult class
hierarchy to type here as this hierarchy passes through
largely amorphous "row" datatypes throughout, which
can in fact by all kinds of different things, like
raw DBAPI rows, or Row objects, or "scalar"/Any, but
at the same time these types have meaning so I tried still
maintaining some level of semantic markings for these,
it highlights how complex Result is now, as it's trying
to be extremely efficient and inlined while also being
very open-ended and extensible.

Change-Id: I98b75c0c09eab5355fc7a33ba41dd9874274f12a
2022-03-01 09:09:02 -05:00
luz paz 56256b6d13 Fix various source comment/doc typos
### Description
Found via `codespell -q 3 -L ba,crate,datas,froms,gord,hist,inh,nd,selectin,strat,ue`
Also added codespell to the pep8 tox env

### Checklist

This pull request is:

- [x] A documentation / typographical error fix
	- Good to go, no issue or tests are needed

Closes: #7338
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7338
Pull-request-sha: 0deac22193

Change-Id: Icd61db31c8dc655d4a39d8a304194804d08555fe
2021-12-29 21:35:34 +01:00
Mike Bayer f05d3ddba4 initial 2.0 setup
Adapted from 55e64f857daeb6057b85ff67297a774b when we
previously started a 2.0 branch.

Change-Id: Ib5af75df94b23104eebe0e918adcf979d798ea3b
2021-10-30 14:21:53 -04:00
Mike Bayer 7cf3e79991 add sections for ORM use with UNION
this is a fairly non-obvious part of the new ORM
querying style and needs its own sections

Change-Id: Iacb176020d580066c1e0b7f2b40bfbbcb3587d76
2021-10-25 22:22:27 -04:00
JMcB17 222ea42ec5 Remove misplaced apostrophe in tutorial/index.rst (#7043)
Citation: http://www.sussex.ac.uk/informatics/punctuation/apostrophe/possessives
2021-09-19 18:30:24 +02:00
Kevin Kirsche a4abb4e396 fix: typos in doc/build/tutorial (#7005) 2021-09-08 21:14:56 +02:00
jonathan vanasco 369edbbd67 standardizing docs #6821
(redo of 2999/I5609025feee8cfdecc09b55bfbf1bd13fa2e6602)

This PR is designed to bring more clarity within the docs by renaming object
instances that may be consfusingly similar to class, method, and attribute names.

For example, instances of the class `MetaData` are available on some  objects as
`.metadata` property, and had appeared within the docs as both `meta` and
`metadata` which has confused some users in the past. By this PR, the docs now
utilize the following naming convention:

* MetaData - SQLAlchemy class
* .metadata - SQLAlchemy API attributes
* metadata_obj - developer instantiated metadata objects or references

Detailed Changes:

* standardized `meta` and `metadata` instances to `metadata_obj`. note: the docs were evenly split between 'meta' and 'metadata'.
* standardized 'cursor' to 'cursor_obj' to avoid confusion with the method.
* standardized a 'scalar_subquery = ' to 'scalar_subq' to avoid confusion with the method.
* standardized a 'cte = ' to 'cte_obj' to avoid confusion with the method

Change-Id: I79c98aee16c5fc6649289b2dd7d6dfc368222fb4
2021-08-23 16:25:21 -04:00
Federico Caselli fb81f9c8d9 Replace all http:// links to https://
Also replace http://pypi.python.org/pypi with https://pypi.org/project

Change-Id: I84b5005c39969a82140706472989f2a30b0c7685
2021-07-04 20:54:33 +02:00
Samuel Cattini-Schultz f0ad41eb6f Fix typos in "Working with Related Objects" docs (#6651)
* Fix typo in "Working with Related Objects" docs

* Fix typo in "Working with Related Objects" docs
2021-06-17 20:51:38 +02:00
Sebastián Ramírez 5b12393e81 ✏️ Fix minor typos in "Selecting Rows with Core or ORM" (#6381) 2021-04-28 20:42:12 +02:00
Sebastián Ramírez d69407abdb ✏️ Fix typos in "Data Manipulation with the ORM" (#6389) 2021-04-28 20:42:07 +02:00
Sebastián Ramírez 59afa4f6f4 ✏️ Fix typos in "Working with Related Objects" (#6393) 2021-04-28 20:41:54 +02:00
Sebastián Ramírez e39e5ff88c ✏️ Fix small typo in "Updating and Deleting Rows with Core" (#6382) 2021-04-28 20:39:29 +02:00
Sebastián Ramírez 2af1b107fc ✏️ Fix small typos in "Working with Database Metadata" (#6369) 2021-04-27 22:22:38 +02:00
Sebastián Ramírez f81b71175d ✏️ Fix small formatting typo in "Working with Data" (#6370) 2021-04-27 22:22:01 +02:00
Sebastián Ramírez cf329ec331 ✏️ Fix small typos in SQLAlchemy 1.4 / 2.0 Tutorial (#6358)
* ✏️ Fix small typos in SQLAlchemy 1.4 / 2.0 Tutorial

*  Revert bikeshedding about "they", "we"

as I'm not sure changing to "they" actually helps disambiguate or not, so better to leave as it is.
2021-04-26 21:49:38 +02:00
Sebastián Ramírez b51850fd88 ✏️ Fix small typo in Working with Transactions and the DBAPI (#6363) 2021-04-26 21:49:02 +02:00
Mike Bayer 1443945e61 Add order by to union example
the query in the second union example needs order by to
produce determinstic results on all plaforms including
OSX, arm

Change-Id: I88fcc391561db8567c389ed9e904e5de29c1c2ad
2021-04-23 19:15:48 -04:00
Mike Bayer fb9e12a689 Break up data.rst; add unions, literal_column
This breaks data.rst into three separate sub-sections,
as SELECT is getting very long.  It then adds sections
on select() + text/literal_column as well as unions
and set operations, and also tries to improve the
ORDER BY section a bit.

Change-Id: Id90e6b4ff3699b2bbcb6e2eebbd23193e2ede00a
2021-04-22 16:44:35 -04:00
Mike Bayer a58c99977e add some cross-linking for orderby/groupby docs + label examples
Change-Id: I34d4958ded8ec95e439ee47fdcb600f357cf7ae3
References: #6324
2021-04-19 11:45:09 -04:00
Mike Bayer 41de9a86c0 Return Row for CursorResult.inserted_primary_key
The tuple returned by :attr:`.CursorResult.inserted_primary_key` is now a
:class:`_result.Row` object with a named tuple interface on top of the
existing tuple interface.

Fixes: #3314
Change-Id: I85677ef60d8329648f368bf497f634758f4e087b
2021-04-11 17:15:55 -04:00
Mike Bayer 6f16636142 Clarify select_from(A).join(B.a)
Fixes: #2722
Change-Id: I025715023fa74b1f9ade4ecc8ed8712f42de727a
2021-04-11 11:10:20 -04:00
Mike Bayer 42185a1f38 document rowcount for ORM update/delete
Change-Id: I16f50cb50fc3cccc1bd7cae3a64a085b1ea68612
2021-03-31 09:42:47 -04:00
mgjo5899 365e5295b8 earler -> earlier 2021-03-21 15:40:44 -05:00
Mike Bayer 930e1a8937 refer to row elements as "elements", not columns
disambiguate between the "elements of a row" and
a "column" which is taken to mean a database column, and
remove confusing terms like "single-column ORM entity".

Change-Id: I7304bdb6dd0f60ab0c36ef3ae40b1f36b29ea291
2021-02-22 22:14:41 -05:00
Federico Caselli 227fd31d7d Fix typo on tutorial/data.rst
Change-Id: Ib7f7a92e2ae15c732659525170118288aebad9a2
2021-02-18 18:51:18 +01:00
Mike Bayer 0698992bfd fix repeated footnote
Change-Id: Ibd8239907c3cf747d0d9a0fb670e37c9913871f8
2021-02-15 11:22:13 -05:00
Mike Bayer 8fc36f3b56 Repair tests for older SQLite, timing, pypy
Change-Id: I9e425d2415d18a893342244755c7748b546fb20d
2021-02-03 16:47:53 -05:00
Mike Bayer afcab5edf6 Implement support for functions as FROM with columns clause support
Implemented support for "table valued functions" along with additional
syntaxes supported by PostgreSQL, one of the most commonly requested
features. Table valued functions are SQL functions that return lists of
values or rows, and are prevalent in PostgreSQL in the area of JSON
functions, where the "table value" is commonly referred towards as the
"record" datatype. Table valued functions are also supported by Oracle and
SQL Server.

Moved from I5b093b72533ef695293e737eb75850b9713e5e03 due
to accidental push

Fixes: #3566
Change-Id: Iea36d04c80a5ed3509dcdd9ebf0701687143fef5
2021-02-03 15:52:17 -05:00
Gord Thompson 22f65156bb Replace with_labels() and apply_labels() in ORM/Core
Replace :meth:`_orm.Query.with_labels` and
:meth:`_sql.GenerativeSelect.apply_labels` with explicit getters and
setters ``get_label_style`` and ``set_label_style`` to accommodate the
three supported label styles: ``LABEL_STYLE_DISAMBIGUATE_ONLY`` (default),
``LABEL_STYLE_TABLENAME_PLUS_COL``, and ``LABEL_STYLE_NONE``.

In addition, for Core and "future style" ORM queries,
``LABEL_STYLE_DISAMBIGUATE_ONLY`` is now the default label style. This
style differs from the existing "no labels" style in that labeling is
applied in the case of column name conflicts; with ``LABEL_STYLE_NONE``, a
duplicate column name is not accessible via name in any case.

For legacy ORM queries using :class:`_query.Query`, the table-plus-column
names labeling style applied by ``LABEL_STYLE_TABLENAME_PLUS_COL``
continues to be used so that existing test suites and logging facilities
see no change in behavior by default, however this style of labeling is no
longer required for SQLAlchemy queries to function, as result sets are
commonly matched to columns using a positional approach since SQLAlchemy
1.0.

Within test suites, all use of apply_labels()  / use_labels
now uses the new methods.    New tests added to
test/sql/test_deprecations.py nad test/orm/test_deprecations.py
to cover just the old apply_labels() method call.  Tests
in ORM that made explicit use apply_labels()/ etc. where it isn't needed
for the ORM to work correctly use default label style now.

Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com>
Fixes: #4757
Change-Id: I5fdcd2ed4ae8c7fe62f8be2b6d0e8f66409b6a54
2021-01-26 16:52:30 -05:00
Mike Bayer 851a3a362e Revert "Implement support for functions as FROM with columns clause support"
This reverts commit 05a31f2708.

Atom has this little button called "push" and just pushes to master,
I wasn't even *on* master.  oops
2021-01-21 11:15:06 -05:00
Mike Bayer 05a31f2708 Implement support for functions as FROM with columns clause support
WIP

Fixes: #3566
Change-Id: I5b093b72533ef695293e737eb75850b9713e5e03
2021-01-20 23:30:21 -05:00
Evan Moore 4d20df1484 Fix docs typo: subuqery -> subquery
<!-- Provide a general summary of your proposed changes in the Title field above -->

### Description
Fixes #5839
(sorry, realized just now that an issue wasn't required)

### Checklist
<!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once)

-->

This pull request is:

- [x] A documentation / typographical error fix
	- Good to go, no issue or tests are needed
- [ ] A short code fix
	- please include the issue number, and create an issue if none exists, which
	  must include a complete example of the issue.  one line code fixes without an
	  issue and demonstration will not be accepted.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.   one line code fixes without tests will not be accepted.
- [ ] A new feature implementation
	- please include the issue number, and create an issue if none exists, which must
	  include a complete example of how the feature would look.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.

**Have a nice day!**

Closes: #5840
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5840
Pull-request-sha: b6f6af929f

Change-Id: I0b4c9b2d893e8141ee1cd21742a9b111fe371bac
2021-01-14 03:22:48 -05:00
Mike Bayer 0c8c7b6656 improve cross-linking between Core /ORM for schema arg
this should be backported to 1.3 as well to as much a degree
as possible.

Includes a new recipe to set the default schema name
on connect.   this will only work on 1.4, but also requires
that we fix #5708 for it to work fully.

Change-Id: I882edd5bbe06ee5b4d0a9c148854a57b2bcd4741
2020-11-30 19:07:36 -05:00
Mike Bayer 7082e4c447 Clarify how ORM rows are returned in the tutorial
The ORM querying guide discussed how rows are returned but
the tutorial fails to introduce this important concept.

Fixes: #5706
Change-Id: I8c9585e28841b5dd86f4ab642f57cbc763635425
2020-11-17 09:58:56 -05:00