From 733181b7a6e71597df0a63581dec7f5828fef464 Mon Sep 17 00:00:00 2001 From: CoprDistGit Date: Thu, 18 May 2023 05:31:45 +0000 Subject: automatic import of python-buildpg --- .gitignore | 1 + python-buildpg.spec | 657 ++++++++++++++++++++++++++++++++++++++++++++++++++++ sources | 1 + 3 files changed, 659 insertions(+) create mode 100644 python-buildpg.spec create mode 100644 sources diff --git a/.gitignore b/.gitignore index e69de29..c5f8493 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +/buildpg-0.4.tar.gz diff --git a/python-buildpg.spec b/python-buildpg.spec new file mode 100644 index 0000000..8cf924f --- /dev/null +++ b/python-buildpg.spec @@ -0,0 +1,657 @@ +%global _empty_manifest_terminate_build 0 +Name: python-buildpg +Version: 0.4 +Release: 1 +Summary: Query building for the postgresql prepared statements and asyncpg. +License: MIT +URL: https://github.com/samuelcolvin/buildpg +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/48/f2/ff0e51a3c2390538da6eb4f85e30d87aafbcc6d057c6c9bb9fa222c8f2fc/buildpg-0.4.tar.gz +BuildArch: noarch + + +%description +# buildpg + +[![CI](https://github.com/samuelcolvin/buildpg/workflows/ci/badge.svg?event=push)](https://github.com/samuelcolvin/buildpg/actions?query=event%3Apush+branch%3Amaster+workflow%3Aci) +[![Coverage](https://codecov.io/gh/samuelcolvin/buildpg/branch/master/graph/badge.svg)](https://codecov.io/gh/samuelcolvin/buildpg) +[![pypi](https://img.shields.io/pypi/v/buildpg.svg)](https://pypi.python.org/pypi/buildpg) +[![versions](https://img.shields.io/pypi/pyversions/buildpg.svg)](https://github.com/samuelcolvin/buildpg) +[![license](https://img.shields.io/github/license/samuelcolvin/buildpg.svg)](https://github.com/samuelcolvin/buildpg/blob/master/LICENSE) + +Query building for the postgresql prepared statements and asyncpg. + +Lots of more powerful features, including full clause construction, multiple values, logic functions, +query pretty-printing and different variable substitution - below is just a very quick summary. +Please check the code and tests for examples. + +## Building Queries + +Simple variable substitution: + +```py +from buildpg import render + +render('select * from mytable where x=:foo and y=:bar', foo=123, bar='whatever') +>> 'select * from mytable where x=$1 and y=$2', [123, 'whatever'] +``` + + +Use of `V` to substitute constants: + +```py +from buildpg import V, render + +render('select * from mytable where :col=:foo', col=V('x'), foo=456) +>> 'select * from mytable where x=$1', [456] +``` + +Complex logic: + +```py +from buildpg import V, funcs, render + +where_logic = V('foo.bar') == 123 +if spam_value: + where_logic &= V('foo.spam') <= spam_value + +if exclude_cake: + where_logic &= funcs.not_(V('foo.cake').in_([1, 2, 3])) + +render('select * from foo :where', where=where_logic) +>> 'select * from foo foo.bar = $1 AND foo.spam <= $2 AND not(foo.cake in $3)', [123, 123, ['x', 'y']] +``` + +Values usage: + +```py +from buildpg import Values, render + +render('insert into the_table (:values__names) values :values', values=Values(a=123, b=456, c='hello')) +>> 'insert into the_table (a, b, c) values ($1, $2, $3)', [123, 456, 'hello'] +``` + +## With asyncpg + +As a wrapper around *asyncpg*: + +```py +import asyncio +from buildpg import asyncpg + +async def main(): + async with asyncpg.create_pool_b('postgres://postgres@localhost:5432/db') as pool: + await pool.fetchval_b('select spam from mytable where x=:foo and y=:bar', foo=123, bar='whatever') + >> 42 + +asyncio.run(main()) +``` + + +Both the pool and connections have `*_b` variants of all common query methods: + +- `execute_b` +- `executemany_b` +- `fetch_b` +- `fetchval_b` +- `fetchrow_b` +- `cursor_b` + + +## Operators + +| Python operator/function | SQL operator | +| ------------------------ | ------------ | +| `&` | `AND` | +| `|` | `OR` | +| `=` | `=` | +| `!=` | `!=` | +| `<` | `<` | +| `<=` | `<=` | +| `>` | `>` | +| `>=` | `>=` | +| `+` | `+` | +| `-` | `-` | +| `*` | `*` | +| `/` | `/` | +| `%` | `%` | +| `**` | `^` | +| `-` | `-` | +| `~` | `not(...)` | +| `sqrt` | `|/` | +| `abs` | `@` | +| `contains` | `@>` | +| `contained_by` | `<@` | +| `overlap` | `&&` | +| `like` | `LIKE` | +| `ilike` | `ILIKE` | +| `cat` | `||` | +| `in_` | `in` | +| `from_` | `from` | +| `at_time_zone` | `AT TIME ZONE` | +| `matches` | `@@` | +| `is_` | `is` | +| `is_not` | `is not` | +| `for_` | `for` | +| `factorial` | `!` | +| `cast` | `::` | +| `asc` | `ASC` | +| `desc` | `DESC` | +| `comma` | `,` | +| `on` | `ON` | +| `as_` | `AS` | +| `nulls_first` | `NULLS FIRST` | +| `nulls_last` | `NULLS LAST` | + +Usage: + +```py +from buildpg import V, S, render + +def show(component): + sql, params = render(':c', c=component) + print(f'sql="{sql}" params={params}') + +show(V('foobar').contains([1, 2, 3])) +#> sql="foobar @> $1" params=[[1, 2, 3]] +show(V('foobar') == 4) +#> sql="foobar = $1" params=[4] +show(~V('foobar')) +#> sql="not(foobar)" params=[] +show(S(625).sqrt()) +#> sql="|/ $1" params=[625] +show(V('foo').is_not('true')) +#> sql="foo is not true" params=[] +``` + +## Functions + +| Python function | SQL function | +| ------------------------------------------- | ------------- | +| `AND(*args)` | ` and ...` | +| `OR(*args)` | ` or ...` | +| `NOT(arg)` | `not()` | +| `comma_sep(*args)` | `, , ...` | +| `count(expr)` | `count(expr)` | +| `any(arg)` | `any()` | +| `now()` | `now()` | +| `cast(v, cast_type)` | `::` | +| `upper(string)` | `upper()` | +| `lower(string)` | `lower()` | +| `length(string)` | `length()` | +| `left(string, n)` | `left(, )` | +| `right(string, n)` | `right(, )` | +| `extract(expr)` | `extract()` | +| `sqrt(n)` | `|/` | +| `abs(n)` | `@` | +| `factorial(n)` | `!` | +| `position(substring, string)` | `position( in from )` | +| `to_tsquery(arg1, text-None)` | `to_tsquery()` | + +Usage: + +```py +from buildpg import V, render, funcs + +def show(component): + sql, params = render(':c', c=component) + print(f'sql="{sql}" params={params}') + +show(funcs.AND(V('x') == 4, V('y') > 6)) +#> sql="x = $1 AND y > $2" params=[4, 6] +show(funcs.position('foo', 'this has foo in it')) +#> sql="position($1 in $2)" params=['foo', 'this has foo in it'] +``` + + + + +%package -n python3-buildpg +Summary: Query building for the postgresql prepared statements and asyncpg. +Provides: python-buildpg +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-buildpg +# buildpg + +[![CI](https://github.com/samuelcolvin/buildpg/workflows/ci/badge.svg?event=push)](https://github.com/samuelcolvin/buildpg/actions?query=event%3Apush+branch%3Amaster+workflow%3Aci) +[![Coverage](https://codecov.io/gh/samuelcolvin/buildpg/branch/master/graph/badge.svg)](https://codecov.io/gh/samuelcolvin/buildpg) +[![pypi](https://img.shields.io/pypi/v/buildpg.svg)](https://pypi.python.org/pypi/buildpg) +[![versions](https://img.shields.io/pypi/pyversions/buildpg.svg)](https://github.com/samuelcolvin/buildpg) +[![license](https://img.shields.io/github/license/samuelcolvin/buildpg.svg)](https://github.com/samuelcolvin/buildpg/blob/master/LICENSE) + +Query building for the postgresql prepared statements and asyncpg. + +Lots of more powerful features, including full clause construction, multiple values, logic functions, +query pretty-printing and different variable substitution - below is just a very quick summary. +Please check the code and tests for examples. + +## Building Queries + +Simple variable substitution: + +```py +from buildpg import render + +render('select * from mytable where x=:foo and y=:bar', foo=123, bar='whatever') +>> 'select * from mytable where x=$1 and y=$2', [123, 'whatever'] +``` + + +Use of `V` to substitute constants: + +```py +from buildpg import V, render + +render('select * from mytable where :col=:foo', col=V('x'), foo=456) +>> 'select * from mytable where x=$1', [456] +``` + +Complex logic: + +```py +from buildpg import V, funcs, render + +where_logic = V('foo.bar') == 123 +if spam_value: + where_logic &= V('foo.spam') <= spam_value + +if exclude_cake: + where_logic &= funcs.not_(V('foo.cake').in_([1, 2, 3])) + +render('select * from foo :where', where=where_logic) +>> 'select * from foo foo.bar = $1 AND foo.spam <= $2 AND not(foo.cake in $3)', [123, 123, ['x', 'y']] +``` + +Values usage: + +```py +from buildpg import Values, render + +render('insert into the_table (:values__names) values :values', values=Values(a=123, b=456, c='hello')) +>> 'insert into the_table (a, b, c) values ($1, $2, $3)', [123, 456, 'hello'] +``` + +## With asyncpg + +As a wrapper around *asyncpg*: + +```py +import asyncio +from buildpg import asyncpg + +async def main(): + async with asyncpg.create_pool_b('postgres://postgres@localhost:5432/db') as pool: + await pool.fetchval_b('select spam from mytable where x=:foo and y=:bar', foo=123, bar='whatever') + >> 42 + +asyncio.run(main()) +``` + + +Both the pool and connections have `*_b` variants of all common query methods: + +- `execute_b` +- `executemany_b` +- `fetch_b` +- `fetchval_b` +- `fetchrow_b` +- `cursor_b` + + +## Operators + +| Python operator/function | SQL operator | +| ------------------------ | ------------ | +| `&` | `AND` | +| `|` | `OR` | +| `=` | `=` | +| `!=` | `!=` | +| `<` | `<` | +| `<=` | `<=` | +| `>` | `>` | +| `>=` | `>=` | +| `+` | `+` | +| `-` | `-` | +| `*` | `*` | +| `/` | `/` | +| `%` | `%` | +| `**` | `^` | +| `-` | `-` | +| `~` | `not(...)` | +| `sqrt` | `|/` | +| `abs` | `@` | +| `contains` | `@>` | +| `contained_by` | `<@` | +| `overlap` | `&&` | +| `like` | `LIKE` | +| `ilike` | `ILIKE` | +| `cat` | `||` | +| `in_` | `in` | +| `from_` | `from` | +| `at_time_zone` | `AT TIME ZONE` | +| `matches` | `@@` | +| `is_` | `is` | +| `is_not` | `is not` | +| `for_` | `for` | +| `factorial` | `!` | +| `cast` | `::` | +| `asc` | `ASC` | +| `desc` | `DESC` | +| `comma` | `,` | +| `on` | `ON` | +| `as_` | `AS` | +| `nulls_first` | `NULLS FIRST` | +| `nulls_last` | `NULLS LAST` | + +Usage: + +```py +from buildpg import V, S, render + +def show(component): + sql, params = render(':c', c=component) + print(f'sql="{sql}" params={params}') + +show(V('foobar').contains([1, 2, 3])) +#> sql="foobar @> $1" params=[[1, 2, 3]] +show(V('foobar') == 4) +#> sql="foobar = $1" params=[4] +show(~V('foobar')) +#> sql="not(foobar)" params=[] +show(S(625).sqrt()) +#> sql="|/ $1" params=[625] +show(V('foo').is_not('true')) +#> sql="foo is not true" params=[] +``` + +## Functions + +| Python function | SQL function | +| ------------------------------------------- | ------------- | +| `AND(*args)` | ` and ...` | +| `OR(*args)` | ` or ...` | +| `NOT(arg)` | `not()` | +| `comma_sep(*args)` | `, , ...` | +| `count(expr)` | `count(expr)` | +| `any(arg)` | `any()` | +| `now()` | `now()` | +| `cast(v, cast_type)` | `::` | +| `upper(string)` | `upper()` | +| `lower(string)` | `lower()` | +| `length(string)` | `length()` | +| `left(string, n)` | `left(, )` | +| `right(string, n)` | `right(, )` | +| `extract(expr)` | `extract()` | +| `sqrt(n)` | `|/` | +| `abs(n)` | `@` | +| `factorial(n)` | `!` | +| `position(substring, string)` | `position( in from )` | +| `to_tsquery(arg1, text-None)` | `to_tsquery()` | + +Usage: + +```py +from buildpg import V, render, funcs + +def show(component): + sql, params = render(':c', c=component) + print(f'sql="{sql}" params={params}') + +show(funcs.AND(V('x') == 4, V('y') > 6)) +#> sql="x = $1 AND y > $2" params=[4, 6] +show(funcs.position('foo', 'this has foo in it')) +#> sql="position($1 in $2)" params=['foo', 'this has foo in it'] +``` + + + + +%package help +Summary: Development documents and examples for buildpg +Provides: python3-buildpg-doc +%description help +# buildpg + +[![CI](https://github.com/samuelcolvin/buildpg/workflows/ci/badge.svg?event=push)](https://github.com/samuelcolvin/buildpg/actions?query=event%3Apush+branch%3Amaster+workflow%3Aci) +[![Coverage](https://codecov.io/gh/samuelcolvin/buildpg/branch/master/graph/badge.svg)](https://codecov.io/gh/samuelcolvin/buildpg) +[![pypi](https://img.shields.io/pypi/v/buildpg.svg)](https://pypi.python.org/pypi/buildpg) +[![versions](https://img.shields.io/pypi/pyversions/buildpg.svg)](https://github.com/samuelcolvin/buildpg) +[![license](https://img.shields.io/github/license/samuelcolvin/buildpg.svg)](https://github.com/samuelcolvin/buildpg/blob/master/LICENSE) + +Query building for the postgresql prepared statements and asyncpg. + +Lots of more powerful features, including full clause construction, multiple values, logic functions, +query pretty-printing and different variable substitution - below is just a very quick summary. +Please check the code and tests for examples. + +## Building Queries + +Simple variable substitution: + +```py +from buildpg import render + +render('select * from mytable where x=:foo and y=:bar', foo=123, bar='whatever') +>> 'select * from mytable where x=$1 and y=$2', [123, 'whatever'] +``` + + +Use of `V` to substitute constants: + +```py +from buildpg import V, render + +render('select * from mytable where :col=:foo', col=V('x'), foo=456) +>> 'select * from mytable where x=$1', [456] +``` + +Complex logic: + +```py +from buildpg import V, funcs, render + +where_logic = V('foo.bar') == 123 +if spam_value: + where_logic &= V('foo.spam') <= spam_value + +if exclude_cake: + where_logic &= funcs.not_(V('foo.cake').in_([1, 2, 3])) + +render('select * from foo :where', where=where_logic) +>> 'select * from foo foo.bar = $1 AND foo.spam <= $2 AND not(foo.cake in $3)', [123, 123, ['x', 'y']] +``` + +Values usage: + +```py +from buildpg import Values, render + +render('insert into the_table (:values__names) values :values', values=Values(a=123, b=456, c='hello')) +>> 'insert into the_table (a, b, c) values ($1, $2, $3)', [123, 456, 'hello'] +``` + +## With asyncpg + +As a wrapper around *asyncpg*: + +```py +import asyncio +from buildpg import asyncpg + +async def main(): + async with asyncpg.create_pool_b('postgres://postgres@localhost:5432/db') as pool: + await pool.fetchval_b('select spam from mytable where x=:foo and y=:bar', foo=123, bar='whatever') + >> 42 + +asyncio.run(main()) +``` + + +Both the pool and connections have `*_b` variants of all common query methods: + +- `execute_b` +- `executemany_b` +- `fetch_b` +- `fetchval_b` +- `fetchrow_b` +- `cursor_b` + + +## Operators + +| Python operator/function | SQL operator | +| ------------------------ | ------------ | +| `&` | `AND` | +| `|` | `OR` | +| `=` | `=` | +| `!=` | `!=` | +| `<` | `<` | +| `<=` | `<=` | +| `>` | `>` | +| `>=` | `>=` | +| `+` | `+` | +| `-` | `-` | +| `*` | `*` | +| `/` | `/` | +| `%` | `%` | +| `**` | `^` | +| `-` | `-` | +| `~` | `not(...)` | +| `sqrt` | `|/` | +| `abs` | `@` | +| `contains` | `@>` | +| `contained_by` | `<@` | +| `overlap` | `&&` | +| `like` | `LIKE` | +| `ilike` | `ILIKE` | +| `cat` | `||` | +| `in_` | `in` | +| `from_` | `from` | +| `at_time_zone` | `AT TIME ZONE` | +| `matches` | `@@` | +| `is_` | `is` | +| `is_not` | `is not` | +| `for_` | `for` | +| `factorial` | `!` | +| `cast` | `::` | +| `asc` | `ASC` | +| `desc` | `DESC` | +| `comma` | `,` | +| `on` | `ON` | +| `as_` | `AS` | +| `nulls_first` | `NULLS FIRST` | +| `nulls_last` | `NULLS LAST` | + +Usage: + +```py +from buildpg import V, S, render + +def show(component): + sql, params = render(':c', c=component) + print(f'sql="{sql}" params={params}') + +show(V('foobar').contains([1, 2, 3])) +#> sql="foobar @> $1" params=[[1, 2, 3]] +show(V('foobar') == 4) +#> sql="foobar = $1" params=[4] +show(~V('foobar')) +#> sql="not(foobar)" params=[] +show(S(625).sqrt()) +#> sql="|/ $1" params=[625] +show(V('foo').is_not('true')) +#> sql="foo is not true" params=[] +``` + +## Functions + +| Python function | SQL function | +| ------------------------------------------- | ------------- | +| `AND(*args)` | ` and ...` | +| `OR(*args)` | ` or ...` | +| `NOT(arg)` | `not()` | +| `comma_sep(*args)` | `, , ...` | +| `count(expr)` | `count(expr)` | +| `any(arg)` | `any()` | +| `now()` | `now()` | +| `cast(v, cast_type)` | `::` | +| `upper(string)` | `upper()` | +| `lower(string)` | `lower()` | +| `length(string)` | `length()` | +| `left(string, n)` | `left(, )` | +| `right(string, n)` | `right(, )` | +| `extract(expr)` | `extract()` | +| `sqrt(n)` | `|/` | +| `abs(n)` | `@` | +| `factorial(n)` | `!` | +| `position(substring, string)` | `position( in from )` | +| `to_tsquery(arg1, text-None)` | `to_tsquery()` | + +Usage: + +```py +from buildpg import V, render, funcs + +def show(component): + sql, params = render(':c', c=component) + print(f'sql="{sql}" params={params}') + +show(funcs.AND(V('x') == 4, V('y') > 6)) +#> sql="x = $1 AND y > $2" params=[4, 6] +show(funcs.position('foo', 'this has foo in it')) +#> sql="position($1 in $2)" params=['foo', 'this has foo in it'] +``` + + + + +%prep +%autosetup -n buildpg-0.4 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-buildpg -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Thu May 18 2023 Python_Bot - 0.4-1 +- Package Spec generated diff --git a/sources b/sources new file mode 100644 index 0000000..8f358d1 --- /dev/null +++ b/sources @@ -0,0 +1 @@ +1e3c523df94be37397684d65dcba8e05 buildpg-0.4.tar.gz -- cgit v1.2.3