Skip to content

Commit

Permalink
rename query_one to query_single
Browse files Browse the repository at this point in the history
Changes:
- added query_single()
- added query_single_json()
- deprecated query_one()
- deprecated query_one_json()
- renamed files, tests, and variables that used `fetch` in the name
  because it seems like we have effectivly renamed the fetch concept to
  query.
  • Loading branch information
fmoor committed Aug 6, 2021
1 parent 337b779 commit f6900b0
Show file tree
Hide file tree
Showing 18 changed files with 238 additions and 206 deletions.
48 changes: 24 additions & 24 deletions docs/api/asyncio_con.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Connection
>>> import edgedb
>>> async def main():
... con = await edgedb.async_connect(user='edgedeb')
... print(await con.query_one('SELECT 1 + 1'))
... print(await con.query_single('SELECT 1 + 1'))
...
>>> asyncio.run(main())
{2}
Expand Down Expand Up @@ -134,7 +134,7 @@ Connection
Note that positional and named query arguments cannot be mixed.


.. py:coroutinemethod:: query_one(query, *args, **kwargs)
.. py:coroutinemethod:: query_single(query, *args, **kwargs)
Run a singleton-returning query and return its element.

Expand Down Expand Up @@ -179,7 +179,7 @@ Connection
more appropriate type, such as ``Decimal``.


.. py:coroutinemethod:: query_one_json(query, *args, **kwargs)
.. py:coroutinemethod:: query_single_json(query, *args, **kwargs)
Run a singleton-returning query and return its element in JSON.

Expand Down Expand Up @@ -232,7 +232,7 @@ Connection
.. note::
If the results of *query* are desired, :py:meth:`query` or
:py:meth:`query_one` should be used instead.
:py:meth:`query_single` should be used instead.

.. py:method:: retrying_transaction()
Expand All @@ -254,7 +254,7 @@ Connection
async for tx in con.retrying_transaction():
async with tx:
value = await tx.query_one("SELECT Counter.value")
value = await tx.query_single("SELECT Counter.value")
await tx.execute(
"UPDATE Counter SET { value := <int64>$value }",
value=value + 1,
Expand Down Expand Up @@ -282,7 +282,7 @@ Connection
.. code-block:: python
async with con.raw_transaction() as tx:
value = await tx.query_one("SELECT Counter.value")
value = await tx.query_single("SELECT Counter.value")
await tx.execute(
"UPDATE Counter SET { value := <int64>$value }",
value=value + 1,
Expand Down Expand Up @@ -368,9 +368,9 @@ Connection Pools
from the pool:

* :py:meth:`AsyncIOPool.query()`
* :py:meth:`AsyncIOPool.query_one()`
* :py:meth:`AsyncIOPool.query_single()`
* :py:meth:`AsyncIOPool.query_json()`
* :py:meth:`AsyncIOPool.query_one_json()`
* :py:meth:`AsyncIOPool.query_single_json()`
* :py:meth:`AsyncIOPool.execute()`
* :py:meth:`AsyncIOPool.retrying_transaction()`
* :py:meth:`AsyncIOPool.raw_transaction()`
Expand Down Expand Up @@ -505,14 +505,14 @@ Connection Pools
See :py:meth:`AsyncIOConnection.query()
<edgedb.AsyncIOConnection.query>` for details.

.. py:coroutinemethod:: query_one(query, *args, **kwargs)
.. py:coroutinemethod:: query_single(query, *args, **kwargs)
Acquire a connection and use it to run a singleton-returning query
and return its element. The temporary connection is automatically
returned back to the pool.

See :py:meth:`AsyncIOConnection.query_one()
<edgedb.AsyncIOConnection.query_one>` for details.
See :py:meth:`AsyncIOConnection.query_single()
<edgedb.AsyncIOConnection.query_single>` for details.

.. py:coroutinemethod:: query_json(query, *args, **kwargs)
Expand All @@ -523,14 +523,14 @@ Connection Pools
See :py:meth:`AsyncIOConnection.query_json()
<edgedb.AsyncIOConnection.query_json>` for details.

.. py:coroutinemethod:: query_one_json(query, *args, **kwargs)
.. py:coroutinemethod:: query_single_json(query, *args, **kwargs)
Acquire a connection and use it to run a singleton-returning
query and return its element in JSON. The temporary connection is
automatically returned back to the pool.

See :py:meth:`AsyncIOConnection.query_one_json()
<edgedb.AsyncIOConnection.query_one_json>` for details.
See :py:meth:`AsyncIOConnection.query_single_json()
<edgedb.AsyncIOConnection.query_single_json>` for details.

.. py:coroutinemethod:: execute(query)
Expand Down Expand Up @@ -561,7 +561,7 @@ Connection Pools
async for tx in pool.retrying_transaction():
async with tx:
value = await tx.query_one("SELECT Counter.value")
value = await tx.query_single("SELECT Counter.value")
await tx.execute(
"UPDATE Counter SET { value := <int64>$value",
value=value,
Expand Down Expand Up @@ -589,7 +589,7 @@ Connection Pools
.. code-block:: python
async with pool.raw_transaction() as tx:
value = await tx.query_one("SELECT Counter.value")
value = await tx.query_single("SELECT Counter.value")
await tx.execute(
"UPDATE Counter SET { value := <int64>$value",
value=value,
Expand Down Expand Up @@ -635,15 +635,15 @@ Python code. Here is an example:
async for tx in pool.retrying_transaction():
async with tx:
user = await tx.query_one(
user = await tx.query_single(
"SELECT User { email } FILTER .login = <str>$login",
login=login,
)
data = await httpclient.get(
'https://service.local/email_info',
params=dict(email=user.email),
)
user = await tx.query_one('''
user = await tx.query_single('''
UPDATE User FILTER .login = <str>$login
SET { email_info := <json>$data}
''',
Expand Down Expand Up @@ -707,14 +707,14 @@ See also:
See :py:meth:`AsyncIOConnection.query()
<edgedb.AsyncIOConnection.query>` for details.

.. py:coroutinemethod:: query_one(query, *args, **kwargs)
.. py:coroutinemethod:: query_single(query, *args, **kwargs)
Acquire a connection and use it to run a singleton-returning query
and return its element. The temporary connection is automatically
returned back to the pool.

See :py:meth:`AsyncIOConnection.query_one()
<edgedb.AsyncIOConnection.query_one>` for details.
See :py:meth:`AsyncIOConnection.query_single()
<edgedb.AsyncIOConnection.query_single>` for details.

.. py:coroutinemethod:: query_json(query, *args, **kwargs)
Expand All @@ -725,14 +725,14 @@ See also:
See :py:meth:`AsyncIOConnection.query_json()
<edgedb.AsyncIOConnection.query_json>` for details.

.. py:coroutinemethod:: query_one_json(query, *args, **kwargs)
.. py:coroutinemethod:: query_single_json(query, *args, **kwargs)
Acquire a connection and use it to run a singleton-returning
query and return its element in JSON. The temporary connection is
automatically returned back to the pool.

See :py:meth:`AsyncIOConnection.query_one_json()
<edgedb.AsyncIOConnection.query_one_json>` for details.
See :py:meth:`AsyncIOConnection.query_single_json()
<edgedb.AsyncIOConnection.query_single_json>` for details.

.. py:coroutinemethod:: execute(query)
Expand Down
16 changes: 8 additions & 8 deletions docs/api/blocking_con.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Connection
>>> import edgedb
>>> con = edgedb.connect(user='edgedeb')
>>> con.query_one('SELECT 1 + 1')
>>> con.query_single('SELECT 1 + 1')
{2}
Expand All @@ -130,7 +130,7 @@ Connection
Note that positional and named query arguments cannot be mixed.


.. py:method:: query_one(query, *args, **kwargs)
.. py:method:: query_single(query, *args, **kwargs)
Run a singleton-returning query and return its element.

Expand Down Expand Up @@ -175,7 +175,7 @@ Connection
more appropriate type, such as ``Decimal``.


.. py:method:: query_one_json(query, *args, **kwargs)
.. py:method:: query_single_json(query, *args, **kwargs)
Run a singleton-returning query and return its element in JSON.

Expand Down Expand Up @@ -228,7 +228,7 @@ Connection
.. note::
If the results of *query* are desired, :py:meth:`query` or
:py:meth:`query_one` should be used instead.
:py:meth:`query_single` should be used instead.

.. py:method:: retrying_transaction()
Expand All @@ -250,7 +250,7 @@ Connection
for tx in con.retrying_transaction():
with tx:
value = tx.query_one("SELECT Counter.value")
value = tx.query_single("SELECT Counter.value")
tx.execute(
"UPDATE Counter SET { value := <int64>$value }",
value=value + 1,
Expand Down Expand Up @@ -278,7 +278,7 @@ Connection
.. code-block:: python
with con.raw_transaction() as tx:
value = tx.query_one("SELECT Counter.value")
value = tx.query_single("SELECT Counter.value")
tx.execute(
"UPDATE Counter SET { value := <int64>$value }",
value=value + 1,
Expand Down Expand Up @@ -355,15 +355,15 @@ Python code. Here is an example:
for tx in pool.retrying_transaction():
with tx:
user = tx.query_one(
user = tx.query_single(
"SELECT User { email } FILTER .login = <str>$login",
login=login,
)
data = httpclient.get(
'https://service.local/email_info',
params=dict(email=user.email),
)
user = tx.query_one('''
user = tx.query_single('''
UPDATE User FILTER .login = <str>$login
SET { email_info := <json>$data}
''',
Expand Down
12 changes: 6 additions & 6 deletions docs/api/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Objects
>>> import edgedb
>>> conn = edgedb.connect()
>>> r = conn.query_one('''
>>> r = conn.query_single('''
... SELECT schema::ObjectType {name}
... FILTER .name = 'std::Object'
... LIMIT 1''')
Expand All @@ -134,7 +134,7 @@ Objects
>>> import edgedb
>>> conn = edgedb.connect()
>>> r = conn.query_one('''
>>> r = conn.query_single('''
... SELECT schema::Property {name, annotations: {name, @value}}
... FILTER .name = 'listen_port'
... AND .source.name = 'cfg::Config'
Expand Down Expand Up @@ -190,7 +190,7 @@ Tuples
>>> import edgedb
>>> conn = edgedb.connect()
>>> r = conn.query_one('''SELECT (1, 'a', [3])''')
>>> r = conn.query_single('''SELECT (1, 'a', [3])''')
>>> r
(1, 'a', [3])
>>> len(r)
Expand All @@ -215,7 +215,7 @@ Named Tuples
>>> import edgedb
>>> conn = edgedb.connect()
>>> r = conn.query_one('''SELECT (a := 1, b := 'a', c := [3])''')
>>> r = conn.query_single('''SELECT (a := 1, b := 'a', c := [3])''')
>>> r
(a := 1, b := 'a', c := [3])
>>> r.b
Expand All @@ -237,7 +237,7 @@ Arrays
>>> import edgedb
>>> conn = edgedb.connect()
>>> r = conn.query_one('''SELECT [1, 2, 3]''')
>>> r = conn.query_single('''SELECT [1, 2, 3]''')
>>> r
[1, 2, 3]
>>> len(r)
Expand All @@ -258,7 +258,7 @@ RelativeDuration
>>> import edgedb
>>> conn = edgedb.connect()
>>> r = conn.query_one('''SELECT <cal::relative_duration>"1 year 2 days"''')
>>> r = conn.query_single('''SELECT <cal::relative_duration>"1 year 2 days"''')
>>> r
<edgedb.RelativeDuration "P1Y2D">
>>> r.months
Expand Down
4 changes: 2 additions & 2 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Below is an example of a connection pool usage:
username = int(request.match_info.get('name'))
# Execute the query on any pool connection
result = await pool.query_one_json(
result = await pool.query_single_json(
'''
SELECT User {first_name, email, bio}
FILTER .name = <str>$username
Expand Down Expand Up @@ -181,7 +181,7 @@ You can also acquire connection from the pool:
.. code-block:: python
async with pool.acquire() as conn:
result = await conn.query_one_json(
result = await conn.query_single_json(
'''
SELECT User {first_name, email, bio}
FILTER .name = <str>$username
Expand Down
8 changes: 4 additions & 4 deletions edgedb/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ def query(self, query: str, *args, **kwargs) -> datatypes.Set:
...

@abc.abstractmethod
def query_one(self, query: str, *args, **kwargs) -> typing.Any:
def query_single(self, query: str, *args, **kwargs) -> typing.Any:
...

@abc.abstractmethod
def query_json(self, query: str, *args, **kwargs) -> str:
...

@abc.abstractmethod
def query_one_json(self, query: str, *args, **kwargs) -> str:
def query_single_json(self, query: str, *args, **kwargs) -> str:
...

# TODO(tailhook) add *args, **kwargs, when they are supported
Expand All @@ -44,15 +44,15 @@ async def query(self, query: str, *args, **kwargs) -> datatypes.Set:
...

@abc.abstractmethod
async def query_one(self, query: str, *args, **kwargs) -> typing.Any:
async def query_single(self, query: str, *args, **kwargs) -> typing.Any:
...

@abc.abstractmethod
async def query_json(self, query: str, *args, **kwargs) -> str:
...

@abc.abstractmethod
async def query_one_json(self, query: str, *args, **kwargs) -> str:
async def query_single_json(self, query: str, *args, **kwargs) -> str:
...

# TODO(tailhook) add *args, **kwargs, when they are supported
Expand Down
Loading

0 comments on commit f6900b0

Please sign in to comment.