Skip to main content

ОРМ для базы данных SQlite

Project description

Documentation MazgaDB

Library made for testing.

Import

You can use 2 types of imports: from mazga_db import MazgaDB or import mazga_db.MazgaDB

Class

Field Type Description
db str database name
data_classes dict data_class (not required to use)

Description

Class creation

db - write with extension data_classes - takes the form {'users': People..}

Example:

from MazgaDB import MazgaDB
db = MazgaDB('users.db', {'users': People})

Methods

create_table

Field Type Description
name_table str table name
param dict table options

Description

Adds a table to the database

Param only takes this form {'column_name1': 'data_type1', 'column_name2': 'data_type2'...}
Accepts data type only from sqlite3

Example:

from mazga_db import MazgaDB
db = MazgaDB('users.db')
db.create_table('users',{'id':'INT', 'fname':'TEXT'})
id fname

append_line

Field Type Description
name_table str table name
values list string values

Description

Adds a line to the table

Example:

db = MazgaDB('users.db')
db.append_line('users', [1,'Mazga'])
id fname
1 Mazga

update_line

Field Type Description
name_table str table name
key1 str key (column)
value1 str key1 value
key2 str key (column)
value2 str key2 value

Description

Updates objects by criteria for certain data

Example:

db = MazgaDB('users.db')
db.update_line('users', key1 = 'id', value1 = '1', key2 = 'fname', value2 = 'Mazga2')
id fname
1 Mazga2

We had a line with id 1 and a fname Mazga his fname changed to Mazga2

delete_line

Field Type Description
name_table str table name
key str key(column)
value str key value

Description

Removes a line from the table

Example:

db = MazgaDB('users.db')
db.delete_line('users', key = 'id', value = 1)
id fname

append_column

Field Type Description
name_table str table name
name_column str column name
type_column str column type

Description

Adds a column to the table

type_column - accepts only types from sqlite3

Example:

db = MazgaDB('users.db')
db.append_column('users', 'lname', 'TEXT')
id fname lname
1 Mazga None

delete_column

Field Type Description
name_table str table name
column str column name

Description

Deletes a column in the table

type_column - accepts only types from sqlite3

Example:

db = MazgaDB('users.db')
db.delete_column('users', 'lname')
id fname
1 Mazga

select

Field Type Description
name_table str table name
key str key(column)
value str key value

Description

Regular SELECT from sqlite3

Example:

db = MazgaDB('users.db')
db.select('users', key = 'id', value = '1')

Output:

[(1, 'Mazga')]

select_class

Field Type Description
name_table str table name
key str key(column)
value str key value
class_data None class to return

Description

Returns values as a class

If the class is not passed will take the class from data_classes ({'name_table': class...}),

If the class is not passed and not in dataclasses, will return a class with data, with class name name_table.title()

Example1:

db = MazgaDB('users.db')
db.select_class('users', key = 'id', value = '1', class_data = People)

Output1:

People(id = 1, fname = 'Mazga')

Example2:

db = MazgaDB('users.db', {'users': People})
db.select_class('users', key = 'id', value = '1')

Output2:

People(id = 1, fname = 'Mazga')

Example3:

db = MazgaDB('users.db')
db.select_class('users', key = 'id', value = '1')

Output3:

Users(id = 1, fname = 'Mazga')

read_table

Field Type Description
name_table str table name
type str type table

Description

Returns a table of characters There are only two types 's'(string table) and 'm' (Markdown table). If the wrong type is entered it will raise an error

Example1:

db = MazgaDB('users.db')
db.read_table('users')

Output1:

id fname
1 Mazga

saw_tables

Description

Accepts nothing

Example:

db = MazgaDB('users.db')
db.saw_tables()

Output:

[('users')]

execute

Field Type Description
sql_request str sql request
param list column name

Description

Normal execute from sqlite3 (no need to write db.conn.commit(), it's already built into the functions)

Example:

db = MazgaDB('users.db')
db.execute('SELECT * FROM users')

Output:

[(1, 'Mazga')]

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

MazgaDB-1.1.2.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

MazgaDB-1.1.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file MazgaDB-1.1.2.tar.gz.

File metadata

  • Download URL: MazgaDB-1.1.2.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for MazgaDB-1.1.2.tar.gz
Algorithm Hash digest
SHA256 69326dee7bf9245913356399c68fe21cfc60238cde77b1d1675d00f440d17e81
MD5 2553a17a8993a18e93bba6a8937b398b
BLAKE2b-256 7b349e1656194f92147fa3ee7fa544a101c746e7445ee4e50f85be508dfb21cf

See more details on using hashes here.

File details

Details for the file MazgaDB-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: MazgaDB-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for MazgaDB-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 391f006ad8c4bb1aef6326737b781e39f24d0a4a9ddc8b3ee977335c965e07ba
MD5 16587e2d9004d48f235e611426538613
BLAKE2b-256 d0c9634d11d743151b69e6abb96bfc86dacdf395a47d2639693bf2d862224138

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