Skip to main content

Sqller

ORM library to build SQLite based application in format model/dao/service.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Installing

At first, you need SQLite3 to be installed. Type following in your terminal:

apt-get install libsqlite3-dev

To install the package type the following in your terminal:

sudo pip install sqller

Running the tests

To run tests type the following in your terminal:

python3 -m pytest

or

python -m pytest

if the previous command doesn't work.

Usage

The usage of the library in real application consists of the following steps:

  • Create a model
  • Create a data access object (DAO)
  • Create a service
  • Use the service

The steps are described below.

Create model

class Chat(metaclass=sqller.ModelMeta):
    NAME = 'chats'
    FIELDS = [
        Field(name="id", dtype="integer", postfix="PRIMARY KEY"),
        Field(name="type", dtype="text"),
        Field(name="last_name", dtype="text"),
        Field(name="first_name", dtype="text"),
        Field(name="username", dtype="text"),
        Field(name="chat_id", dtype="integer")
    ]

Create DAO

class ChatDAO(metaclass=sqller.DAOMeta):
    MODEL = Chat

Create service

class TelegramService(metaclass=sqller.ServiceMeta):
    DB_PATH = config.DATABASE_PATH
    MODELS = [
        models.Chat,
        models.SelectedCriterion
    ]

    @staticmethod
    def save_chat_info(chat: telebot.types.Chat):
        obj_exist_checker = models.Chat(id=chat.id)
        obj = models.Chat(
            type = chat.type,
            last_name = chat.last_name,
            first_name = chat.first_name,
            username = chat.username,
            chat_id=chat.id
        )
        sql_exists = dao.ChatDAO.sql_exists(obj_exist_checker)
        sql_save = dao.ChatDAO.sql_save(obj)
        exists = TelegramService.execute(sql_exists)[0][0]
        if not exists:
            TelegramService.execute(sql_save)

Use service

TelegramService.save_chat_info(chat)

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Metadata

Release files for sqller 1.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqller 1.4.2
File Size Uploaded
sqller-1.4.2.tar.gz 6.0 kB Details

Release files / sqller-1.4.2.tar.gz

Download URL sqller-1.4.2.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0be3c35137b4d56f004a6725b9de9deed99005e82cc3265f6e5ff7ea3f7a8c51
BLAKE2b-256 checksum
How to use checksums
0e262689cc3cb50e03e71797b3cad02a54eb07aec2373cc8c25feebccec48f02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.4.2 requests/2.21.0 setuptools/41.4.0 requests-toolbelt/0.8.0 tqdm/4.36.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

1.4.2 This release

1 release file

1.4.1

2 release files

1.4.0

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page