diff options
author | CoprDistGit <infra@openeuler.org> | 2023-05-18 06:40:57 +0000 |
---|---|---|
committer | CoprDistGit <infra@openeuler.org> | 2023-05-18 06:40:57 +0000 |
commit | e21fee807b95118a275d00277d946bfe51752742 (patch) | |
tree | d494010e63c7a30670eb0a61a86ed395e9d12e69 | |
parent | a0b3f5a1da35455bcc56c3a09636ba81e42a743c (diff) |
automatic import of python-pydbrepo
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python-pydbrepo.spec | 653 | ||||
-rw-r--r-- | sources | 1 |
3 files changed, 655 insertions, 0 deletions
@@ -0,0 +1 @@ +/pydbrepo-0.8.0.tar.gz diff --git a/python-pydbrepo.spec b/python-pydbrepo.spec new file mode 100644 index 0000000..7b4f56f --- /dev/null +++ b/python-pydbrepo.spec @@ -0,0 +1,653 @@ +%global _empty_manifest_terminate_build 0 +Name: python-pydbrepo +Version: 0.8.0 +Release: 1 +Summary: Simple implementation of repository pattern for database connections. +License: MIT +URL: https://github.com/danteay/pydbrepo +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/44/8e/119c43f9e984c8b7968d7702981f7270ddfb681e07b28d24f54b713c11ae/pydbrepo-0.8.0.tar.gz +BuildArch: noarch + +Requires: python3-dateutil +Requires: python3-PyPika + +%description +# PyDBRepo + +Is a simple implementation of the Repository pattern to access data in python, providing extensibility flexibility +and builtin tools to manage databases with this pattern. + +## Supported databases + +- SQLite +- MySQL +- PostgreSQL +- MongoDB +- Amazon QLDB + +## Requirements + +- Python >= 3.7 + +### Postgres + +- psychopg2-binary + +### Mysql + +- mysql-connector-python + +### MongoDB + +- pymongo +- dnspython + +### Amazon QLDB + +- pyqldb + + +## Examples + +### Entity usage + +#### Entity model + +This class brings the build it in methods: + +- `to_dict`: Will take all properties of the created class and will convert it into a dict instance. +- `from_dict`: This will take a dict instance and will set the values of every key into a model property with + the same name. +- `from_record`: It takes an ordered Iterable object with the name of the fields that will be loaded into the model, + and a tuple with the corresponding values + +Entity models will be used with simple class properties or can be used with the `Field` descriptor of the package + +##### Example with simple properties + +```python +from pydbrepo import Entity + +class Model(Entity): + id = None + name = None + +model = Model.from_dict({"id": 1, "name": "some"}) +# Model({"id": 1, "name": "some"}) + +print(model.id) # => 1 +print(model.name) # => some +``` + +##### Example with property decorators + +```python +from pydbrepo import Entity + +class Model(Entity): + def __init__(self): + super().__init__() + + self.id = None + self.name = None + + @property + def id(self): + return self._id + + @id.setter + def id(self, value): + self._id = value + + @property + def name(self): + return self._name + + @name.setter + def name(self, value): + self._name = value + +model = Model.from_dict({"id": 1, "name": "some"}) +# Model({"id": 1, "name": "some"}) + +print(model.id) # => 1 +print(model.name) # => some +``` + +##### Example with Field descriptor + +```python +from pydbrepo import Entity, Field, named_fields + +@named_fields +class Model(Entity): + id = Field(type_=int) + name = Field(type_=str) + +model = Model.from_dict({"id": 1, "name": "some"}) +# Model({"id": 1, "name": "some"}) + +print(model.id) # => 1 +print(model.name) # => some +``` + +##### Example of casting values with Field descriptor + +```python +from uuid import UUID +from pydbrepo import Entity, Field, named_fields + +@named_fields +class Model(Entity): + id = Field(type_=(UUID, str), cast_to=UUID, cast_if=str) + name = Field(type_=str) + +model = Model.from_dict({"id": '10620c02-d80e-4950-b0a2-34a5f2d34ae5', "name": "some"}) +# Model({"id": UUID('10620c02-d80e-4950-b0a2-34a5f2d34ae5'), "name": "some"}) + +print(model.id) # => 10620c02-d80e-4950-b0a2-34a5f2d34ae5 +print(model.name) # => some +``` + +##### Example of casting from a callback function + +```python +from datetime import date, datetime +from pydbrepo import Entity, Field, named_fields + +def cast_epoch(value): + if isinstance(value, date): + return int(value.strftime("%s")) + + if isinstance(value, datetime): + return int(value.timestamp()) + +@named_fields +class Model(Entity): + name = Field(type_=str) + epoch = Field(type_=(int, date, datetime), cast_to=cast_epoch, cast_if=(date, datetime)) + +model = Model.from_dict({"name": "some", "epoch": datetime.now()}) +# Model({"name": "some", "epoch": 1231231231}) + +print(model.name) # => some +print(model.epoch) # => 1231231231 +``` + +##### Example of iterable fields and casting with Field descriptor + +```python +from pydbrepo import Entity, Field, named_fields + +@named_fields +class Item(Entity): + name = Field(type_=str) + price = Field(type_=float) + +@named_fields +class Model(Entity): + id = Field(type_=int) + name = Field(type_=str) + items = Field(type_=list, cast_items_to=Item) + +model = Model.from_dict({ + "id": 1, + "name": "some", + "items": [ + {"name": "some", "price": 5.99}, + {"name": "nothing", "price": 6.99}, + ] +}) +# Model({"id": 1, "name": "some", "items": [Item({"name": "some", "price": 5.99}), Item({"name": "nothing", "price": 6.99})]}) + +print(model.id) # => 1 +print(model.name) # => some +print(model.items) # => [Item({"name": "some", "price": 5.99}), Item({"name": "nothing", "price": 6.99})] +print(model.items[0].price) # => 5.99 +``` + + +%package -n python3-pydbrepo +Summary: Simple implementation of repository pattern for database connections. +Provides: python-pydbrepo +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-pydbrepo +# PyDBRepo + +Is a simple implementation of the Repository pattern to access data in python, providing extensibility flexibility +and builtin tools to manage databases with this pattern. + +## Supported databases + +- SQLite +- MySQL +- PostgreSQL +- MongoDB +- Amazon QLDB + +## Requirements + +- Python >= 3.7 + +### Postgres + +- psychopg2-binary + +### Mysql + +- mysql-connector-python + +### MongoDB + +- pymongo +- dnspython + +### Amazon QLDB + +- pyqldb + + +## Examples + +### Entity usage + +#### Entity model + +This class brings the build it in methods: + +- `to_dict`: Will take all properties of the created class and will convert it into a dict instance. +- `from_dict`: This will take a dict instance and will set the values of every key into a model property with + the same name. +- `from_record`: It takes an ordered Iterable object with the name of the fields that will be loaded into the model, + and a tuple with the corresponding values + +Entity models will be used with simple class properties or can be used with the `Field` descriptor of the package + +##### Example with simple properties + +```python +from pydbrepo import Entity + +class Model(Entity): + id = None + name = None + +model = Model.from_dict({"id": 1, "name": "some"}) +# Model({"id": 1, "name": "some"}) + +print(model.id) # => 1 +print(model.name) # => some +``` + +##### Example with property decorators + +```python +from pydbrepo import Entity + +class Model(Entity): + def __init__(self): + super().__init__() + + self.id = None + self.name = None + + @property + def id(self): + return self._id + + @id.setter + def id(self, value): + self._id = value + + @property + def name(self): + return self._name + + @name.setter + def name(self, value): + self._name = value + +model = Model.from_dict({"id": 1, "name": "some"}) +# Model({"id": 1, "name": "some"}) + +print(model.id) # => 1 +print(model.name) # => some +``` + +##### Example with Field descriptor + +```python +from pydbrepo import Entity, Field, named_fields + +@named_fields +class Model(Entity): + id = Field(type_=int) + name = Field(type_=str) + +model = Model.from_dict({"id": 1, "name": "some"}) +# Model({"id": 1, "name": "some"}) + +print(model.id) # => 1 +print(model.name) # => some +``` + +##### Example of casting values with Field descriptor + +```python +from uuid import UUID +from pydbrepo import Entity, Field, named_fields + +@named_fields +class Model(Entity): + id = Field(type_=(UUID, str), cast_to=UUID, cast_if=str) + name = Field(type_=str) + +model = Model.from_dict({"id": '10620c02-d80e-4950-b0a2-34a5f2d34ae5', "name": "some"}) +# Model({"id": UUID('10620c02-d80e-4950-b0a2-34a5f2d34ae5'), "name": "some"}) + +print(model.id) # => 10620c02-d80e-4950-b0a2-34a5f2d34ae5 +print(model.name) # => some +``` + +##### Example of casting from a callback function + +```python +from datetime import date, datetime +from pydbrepo import Entity, Field, named_fields + +def cast_epoch(value): + if isinstance(value, date): + return int(value.strftime("%s")) + + if isinstance(value, datetime): + return int(value.timestamp()) + +@named_fields +class Model(Entity): + name = Field(type_=str) + epoch = Field(type_=(int, date, datetime), cast_to=cast_epoch, cast_if=(date, datetime)) + +model = Model.from_dict({"name": "some", "epoch": datetime.now()}) +# Model({"name": "some", "epoch": 1231231231}) + +print(model.name) # => some +print(model.epoch) # => 1231231231 +``` + +##### Example of iterable fields and casting with Field descriptor + +```python +from pydbrepo import Entity, Field, named_fields + +@named_fields +class Item(Entity): + name = Field(type_=str) + price = Field(type_=float) + +@named_fields +class Model(Entity): + id = Field(type_=int) + name = Field(type_=str) + items = Field(type_=list, cast_items_to=Item) + +model = Model.from_dict({ + "id": 1, + "name": "some", + "items": [ + {"name": "some", "price": 5.99}, + {"name": "nothing", "price": 6.99}, + ] +}) +# Model({"id": 1, "name": "some", "items": [Item({"name": "some", "price": 5.99}), Item({"name": "nothing", "price": 6.99})]}) + +print(model.id) # => 1 +print(model.name) # => some +print(model.items) # => [Item({"name": "some", "price": 5.99}), Item({"name": "nothing", "price": 6.99})] +print(model.items[0].price) # => 5.99 +``` + + +%package help +Summary: Development documents and examples for pydbrepo +Provides: python3-pydbrepo-doc +%description help +# PyDBRepo + +Is a simple implementation of the Repository pattern to access data in python, providing extensibility flexibility +and builtin tools to manage databases with this pattern. + +## Supported databases + +- SQLite +- MySQL +- PostgreSQL +- MongoDB +- Amazon QLDB + +## Requirements + +- Python >= 3.7 + +### Postgres + +- psychopg2-binary + +### Mysql + +- mysql-connector-python + +### MongoDB + +- pymongo +- dnspython + +### Amazon QLDB + +- pyqldb + + +## Examples + +### Entity usage + +#### Entity model + +This class brings the build it in methods: + +- `to_dict`: Will take all properties of the created class and will convert it into a dict instance. +- `from_dict`: This will take a dict instance and will set the values of every key into a model property with + the same name. +- `from_record`: It takes an ordered Iterable object with the name of the fields that will be loaded into the model, + and a tuple with the corresponding values + +Entity models will be used with simple class properties or can be used with the `Field` descriptor of the package + +##### Example with simple properties + +```python +from pydbrepo import Entity + +class Model(Entity): + id = None + name = None + +model = Model.from_dict({"id": 1, "name": "some"}) +# Model({"id": 1, "name": "some"}) + +print(model.id) # => 1 +print(model.name) # => some +``` + +##### Example with property decorators + +```python +from pydbrepo import Entity + +class Model(Entity): + def __init__(self): + super().__init__() + + self.id = None + self.name = None + + @property + def id(self): + return self._id + + @id.setter + def id(self, value): + self._id = value + + @property + def name(self): + return self._name + + @name.setter + def name(self, value): + self._name = value + +model = Model.from_dict({"id": 1, "name": "some"}) +# Model({"id": 1, "name": "some"}) + +print(model.id) # => 1 +print(model.name) # => some +``` + +##### Example with Field descriptor + +```python +from pydbrepo import Entity, Field, named_fields + +@named_fields +class Model(Entity): + id = Field(type_=int) + name = Field(type_=str) + +model = Model.from_dict({"id": 1, "name": "some"}) +# Model({"id": 1, "name": "some"}) + +print(model.id) # => 1 +print(model.name) # => some +``` + +##### Example of casting values with Field descriptor + +```python +from uuid import UUID +from pydbrepo import Entity, Field, named_fields + +@named_fields +class Model(Entity): + id = Field(type_=(UUID, str), cast_to=UUID, cast_if=str) + name = Field(type_=str) + +model = Model.from_dict({"id": '10620c02-d80e-4950-b0a2-34a5f2d34ae5', "name": "some"}) +# Model({"id": UUID('10620c02-d80e-4950-b0a2-34a5f2d34ae5'), "name": "some"}) + +print(model.id) # => 10620c02-d80e-4950-b0a2-34a5f2d34ae5 +print(model.name) # => some +``` + +##### Example of casting from a callback function + +```python +from datetime import date, datetime +from pydbrepo import Entity, Field, named_fields + +def cast_epoch(value): + if isinstance(value, date): + return int(value.strftime("%s")) + + if isinstance(value, datetime): + return int(value.timestamp()) + +@named_fields +class Model(Entity): + name = Field(type_=str) + epoch = Field(type_=(int, date, datetime), cast_to=cast_epoch, cast_if=(date, datetime)) + +model = Model.from_dict({"name": "some", "epoch": datetime.now()}) +# Model({"name": "some", "epoch": 1231231231}) + +print(model.name) # => some +print(model.epoch) # => 1231231231 +``` + +##### Example of iterable fields and casting with Field descriptor + +```python +from pydbrepo import Entity, Field, named_fields + +@named_fields +class Item(Entity): + name = Field(type_=str) + price = Field(type_=float) + +@named_fields +class Model(Entity): + id = Field(type_=int) + name = Field(type_=str) + items = Field(type_=list, cast_items_to=Item) + +model = Model.from_dict({ + "id": 1, + "name": "some", + "items": [ + {"name": "some", "price": 5.99}, + {"name": "nothing", "price": 6.99}, + ] +}) +# Model({"id": 1, "name": "some", "items": [Item({"name": "some", "price": 5.99}), Item({"name": "nothing", "price": 6.99})]}) + +print(model.id) # => 1 +print(model.name) # => some +print(model.items) # => [Item({"name": "some", "price": 5.99}), Item({"name": "nothing", "price": 6.99})] +print(model.items[0].price) # => 5.99 +``` + + +%prep +%autosetup -n pydbrepo-0.8.0 + +%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-pydbrepo -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Thu May 18 2023 Python_Bot <Python_Bot@openeuler.org> - 0.8.0-1 +- Package Spec generated @@ -0,0 +1 @@ +889676db4cf52ce1d243e0fc2aea9573 pydbrepo-0.8.0.tar.gz |