Giter VIP home page Giter VIP logo

lorelie's Introduction

Lorelie

A module that creates a simple interface ORM for SQLITE for any Python application.

from krytpone.tables import Table
from krytpone.fields import CharField

table = Table('my_table', database_name='my_database', inline_build=True, fields=[
    CharField('name')
])
table.prepare()

The above will create a single table called my_table in the my_database sqlite database and with the a column called name.

By default, when calling the Table instance, a connection will is not automatically established with sqlite. You need to set the inline_build to True and then call prepare to run the table creation sequence.

In order to manage multiple tables in a database, using Database implements additional functionnalities such as migrations (or table state tracking).

from krytpone.tables import Table
from krytpone.fields import CharField

table = Table('my_table', database_name='my_database', fields=[
    CharField('name')
])

database = Database('my_database', tables=[table])
database.makemigrations()
dataase.migrate()
table = database.get_table('my_table')

Migrations

{
    "id": null,
    "date": null,
    "number": 0,
    "indexes": [],
    "tables": [
        {
            "name": "celebrities",
            "fields": [
                {
                    "name": "name",
                    "params": [
                        "name",
                        "varchar(300)",
                        "not null",
                    ]
                }
            ],
            "indexes": {}
        }
    ]
}

Functions

Lower

The Lower function is designed to facilitate text manipulation within your SQLite database by converting each value of a specified column to lowercase. This function is particularly useful for standardizing text data, enabling efficient comparison, sorting, and search operations.

database.objects.annotate('table_name', new_column_name=Lower('column_name'))
SELECT LOWER(column_name) AS new_column_name FROM table_name;

parameters

  • table_name (str): The name of the table where the annotation will be applied.
  • new_column_name (str): The desired name for the new column containing the lowercase values.
  • column_name (str): The name of the column whose values will be converted to lowercase.

Example

Consider a scenario where you have a table named 'employees' with a column named 'full_name', which contains names in various formats (e.g., "John DOE", "Mary Smith", "[email protected]"). You may want to standardize these names to lowercase for consistency and ease of comparison. This can be achieved using the Lower function as follows:

Upper

The Upper function facilitates text manipulation within your SQLite database by converting each value of a specified column to uppercase. This function is particularly useful for standardizing text data, enabling efficient comparison, sorting, and search operations.

database.objects.annotate('table_name', new_column_name=Upper('column_name'))
SELECT UPPER(column_name) AS new_column_name FROM table_name;

parameters

  • table_name (str): The name of the table where the annotation will be applied.
  • new_column_name (str): The desired name for the new column containing the lowercase values.
  • column_name (str): The name of the column whose values will be converted to lowercase.

Example

Consider a scenario where you have a table named 'employees' with a column named 'full_name', which contains names in various formats (e.g., "John DOE", "Mary Smith", "[email protected]"). You may want to standardize these names to lowercase for consistency and ease of comparison. This can be achieved using the Lower function as follows:

Length

The Upper function facilitates text manipulation within your SQLite database by converting each value of a specified column to uppercase. This function is particularly useful for standardizing text data, enabling efficient comparison, sorting, and search operations.

database.objects.annotate('table_name', new_column_name=Length('column_name'))
SELECT LEN(column_name) AS new_column_name FROM table_name;

parameters

  • table_name (str): The name of the table where the annotation will be applied.
  • new_column_name (str): The desired name for the new column containing the lowercase values.
  • column_name (str): The name of the column whose values will be converted to lowercase.

Example

Consider a scenario where you have a table named 'articles' with a column named 'content', which contains textual content of varying lengths. You may want to analyze the distribution of article lengths or filter articles based on their length. This can be achieved using the Length function as follows:

lorelie's People

Contributors

zadigo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.