Skip to main content

This is a library to simplify the use of a SQLite3 database, easy to use, easy to understand.

Project description

NewSimpleSQL

English

Use the easiest SQL programming language with PySimpleSQL!

For now, it only has support for SQLite3

Download

pip install NewSimpleSQL

How connect your database:

-SQLite

from NewSimpleSQL.SimpleSQLite import Database

#With auto commit
database: Database = Database('example_database.db')

#Without auto commit
database: Database = Database('example_database.db', False)

How to create tables in your database:

-SQLite

from NewSimpleSQL.SimpleSQLite import Database

database: Database = Database('example_database.db')

#Create one table
database.simple_create_table({
    "name" : "example_table",
    "columns" : {
        "id" : (int,)
        "default_number" : [int, 0],
        "number_constraints" : {
            "type" : int,
            "constraints" : "CHECK (number_constraints > 18)"
        }
    }
})

#Create multiple tables
database.complicated_create_tables([
    {
        "name" : "example_table_2",
        "columns" : {
            "id" : ID(int),
            "number_of_the_first_table" : int
        },
        "fk" : {
            "number_of_the_first_table" : ("example_table", "default_number")
            # Table column name : (Name of the other table, Column of the other table)
        }
    }
    #Other tables
])

Column Types:

SQLite

  • int = INTEGER
  • float = REAL
  • str = TEXT
  • sqlite3.Blob|Blob = BLOB
  • Numeric() = NUMERIC

IDs, defaults y constraints:

SQLite

  • (id_type[int|str],)|ID(int|str) = id_type PRIMARY KEY
  • [column_type[int|str], value] = column_type DEFAULT value
  • { "type" : type, "constraints" : str } = "type" "constraints"

How to get data from the database:

from NewSimpleSQL.SimpleSQLite import Database

database: Database = Database('example_database.db')

#Get data from one table
database.simple_select_data("table_name", "column1, column2, ..., column_infinity"|"*", 'WHERE column1 = 0 ORDER BY column1'|None, one_fetch=True|False)

#Get data from multiple table
database.complicated_select_data([
    {
        "name" : "table_name",
        "column" : "column1, column2, column3, ..., column_infinity",
        "condition" : "WHERE column1 = 0 ORDER BY column1",
        "fetch" : False
    },
    {
        "name" : "table_name_2",
        "column" : "column1, column2, column3, ..., column_infinity",
        "condition" : "WHERE column2 = 0 ORDER BY column2",
        "fetch" : True
    }
])

How to Insert Data into the Database:

from NewSimpleSQL.SimpleSQLite import Database

database: Database = Database('example_database.db')

#Insert data into a single table
database.simple_insert_data("table_name", (value1, value2, value3, ..., value_infinity))

#Insert data into one or more tables
database.complicated_insert_data({
    "table_name" : (value1, value2, value3, ..., value_infinity),
    "table_name_2" : (value1, value2, value3, ..., value_infinity)
})

How to update data in the database:

from NewSimpleSQL.SimpleSQLite import Database

database: Database = Database('example_database.db')

#Update data in a single table
database.simple_update_data("table_name", 'column1 = 0, column2 = "Hello", column3 = False', 'WHERE column1 != 0')

#Update data in one or more tables
database.complicated_update_data([
    {
        "name" : "example_table",
        "columns" : 'column1 = 0, column4 = "Bye"',
        "condition" : 'WHERE column1 != 0'
    },
    {
        "name" : "example_table_2",
        "columns" : 'column1 = 0, column4 = "Bye"',
        "condition" : 'WHERE column4 != "Bye"'
    }
])

These are all the basic commands.

Español

¡Utiliza el lenguaje de programación SQL más facil con PySimpleSQL!

Por ahora, solo tiene soporte son SQLite3

Descarga

pip install NewSimpleSQL

Como usar la libreria

Importar la libreria:

import NewSimpleSQL

Como conectarte a tu base de datos:

-SQLite

from NewSimpleSQL.SimpleSQLite import Database

#Con auto commit
database: Database = Database('example_database.db')

#Sin auto commit
database: Database = Database('example_database.db', False)

Como crear tablas en tu base de datos:

-SQLite

from NewSimpleSQL.SimpleSQLite import Database

database: Database = Database('example_database.db')

#Crear una tabla
database.simple_create_table({
    "name" : "tabla_de_ejemplo",
    "columns" : {
        "id" : ID()
        "numero_por_defecto" : [int, 0],
        "restriccion_de_numero" : {
            "type" : int,
            "constraints" : "CHECK (restriccion_de_numero > 18)"
        }
    }
})

#Crear varias tablas
database.complicated_create_tables([
    {
        "name" : "tabla_de_ejemplo_2",
        "columns" : {
            "id" : ID(str, auto_increment=False),
            "numero_de_la_primera_tabla" : int
        },
        "fk" : {
            "numero_de_la_primera_tabla" : ("tabla_de_ejemplo", "numero_por_defecto")
            # Nombre de la columna de la tabla : (Nombre de la otra tabla, Columna de la otra tabla)
        }
    }
    #Otras tablas
])

Tipos de columnas:

SQLite

  • int = INTEGER
  • float = REAL
  • str = TEXT
  • sqlite3.Blob|Blob = BLOB
  • Numeric() = NUMERIC

IDs, defaults y constraints:

SQLite

  • ID(int|str, auto_increment=True|False) = id_type PRIMARY KEY
  • (column_type,) = column_type NOT NULL
  • [column_type[int|str], value] = column_type DEFAULT value
  • { "type" : type, "constraints" : str } = "type" "constraints"

Como conseguir datos de la base de datos:

from NewSimpleSQL.SimpleSQLite import Database

database: Database = Database('example_database.db')

#Conseguir datos de una tabla
database.simple_select_data("table_name", "column1, column2, ..., column_infinity"|"*", 'WHERE column1 = 0 ORDER BY column1'|None, one_fetch=True|False)

#Conseguir datos de varias tablas
database.complicated_select_data([
    {
        "name" : "table_name",
        "column" : "column1, column2, column3, ..., column_infinity",
        "condition" : "WHERE column1 = 0 ORDER BY column1",
        "fetch" : False
    },
    {
        "name" : "table_name_2",
        "column" : "column1, column2, column3, ..., column_infinity",
        "condition" : "WHERE column2 = 0 ORDER BY column2",
        "fetch" : True
    }
])

Como insertar datos en la base de datos:

from NewSimpleSQL.SimpleSQLite import Database

database: Database = Database('example_database.db')

#Insertar datos en una sola tabla
database.simple_insert_data("table_name", (value1, value2, value3, ..., value_infinity))

#Insertar datos en una o mas tablas
database.complicated_insert_data({
    "table_name" : (value1, value2, value3, ..., value_infinity),
    "table_name_2" : (value1, value2, value3, ..., value_infinity)
})

Como actualizar datos en la base de datos:

from NewSimpleSQL.SimpleSQLite import Database

database: Database = Database('example_database.db')

#Actualizar datos en una sola tabla
database.simple_update_data("table_name", 'column1 = 0, column2 = "Hola", column3 = False', 'WHERE column1 != 0')

#Actualizar datos en una o mas tablas
database.complicated_update_data([
    {
        "name" : "example_table",
        "columns" : 'column1 = 0, column4 = "Adios"',
        "condition" : 'WHERE column1 != 0'
    },
    {
        "name" : "example_table_2",
        "columns" : 'column1 = 0, column4 = "Adios"',
        "condition" : 'WHERE column4 != "Adios"'
    }
])

Estos son todos los comandos basicos.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

newsimplesql-0.6.0.5.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

NewSimpleSQL-0.6.0.5-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file newsimplesql-0.6.0.5.tar.gz.

File metadata

  • Download URL: newsimplesql-0.6.0.5.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for newsimplesql-0.6.0.5.tar.gz
Algorithm Hash digest
SHA256 a355f0c45f537248c6a678e5624488f61d331673e199597f145378e19c1a5b01
MD5 9ae3da4f1ddad533380a9953244c0c64
BLAKE2b-256 96ab6c8246990e9551dd131197cec2b66feaacd551853d9e93c083c97b104566

See more details on using hashes here.

File details

Details for the file NewSimpleSQL-0.6.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for NewSimpleSQL-0.6.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c0f8c81c2bb62ba5cb930d97e4ca640c271ba647cd0bee5b9efed1c883835cfc
MD5 594c858bdbe193d3248e2160402d9798
BLAKE2b-256 acb7626b3567525d01d5015fdb4ad36b3f9c1c9acbbf4c5e8c3c7fbe008db445

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page