@@ -13,7 +13,7 @@ Here you can find some explanations and examples for Sqllex ORM <br>
1313 - [ PostgreSQLx] ( about-postgresqlx.md )
1414 - [ PostgreSQLxTable] ( about-table.md )
1515 - [ AbstractColumn] ( about-column.md )
16- - [ SearchCondition] ( searchcondition- about.md)
16+ - [ SearchCondition] ( about-searchcondition .md )
1717 - [ Project Showcase] ( sqllex-showcase.md )
1818
1919---
@@ -25,38 +25,146 @@ Here you can find some explanations and examples for Sqllex ORM <br>
2525Sqllex is a python ORM library for comfortable and safe interaction with databases.
2626
2727If you've ever worked with databases using python, you know what does "Eat nails while writing SQL-scripts" means.
28- So give a sqllex deal with it, just call needed method, give it a data or necessary parameters and it's done.
29- There no ` con.cursor() ` , only human ` db.insert() ` , ` db.select() ` , ` db['my_table'] ` ,
30- only beautiful and pythonic code without unnecessary SQL-witchcrafting.
31-
32- Sqllex is not like other ORM's, has unfriendly API and awesome for beginners (and not only).
33- By the reason it is just an add-on for sqlite3, there will be easy to find explains for typical sqlite3 raised errors.
34- And any moment you could call ` db.execute() ` method and run any sql-script directly in sqlite3.
28+ So give a sqllex deal with it, just call needed method, give it a data or necessary parameters and done.
3529
36- It'll be a lot easier to show then explain. So down below is a few examples.
30+ THERE NO ` con.cursor() ` , only human ` db.insert() ` , ` db.select() ` , ` db['table'] ` ,
31+ only beautiful and pythonic code without unnecessary SQL-witchcrafting.
3732
38- ### If you never used SQLite before read [ this awesome example #0 ] ( sqlite3x-aex-0.md )
33+ Sqllex has friendly API, documentation and it's awesome for beginners (but not only).
34+ By the reason it is just an add-on for sqlite3/psycopg2, there will be easy to find explains for typical sqlite3 raised errors.
35+ And also in any moment you can call ` db.execute() ` method and run any sql-script directly in the database.
3936
40- ### Otherwise, you can check out [ this one example # 1 ] ( sqlite3x-aex-1.md )
37+ It'll be a lot easier to show then explain. So check out examples down below.
4138
42- ### [ Project showcase ] ( sqllex-showcase.md )
39+ ---
4340
44- # Pages
41+ ## Pages
4542
4643- ### [ SQLite3x] ( about-sqlite3x.md )
4744 - [ SQLite3xTable] ( about-table.md )
48- - Examples
49- - [ Awesome example #0 ] ( sqlite3x-aex-0.md )
50- - [ Awesome example #1 ] ( sqlite3x-aex-1.md )
45+ - ** Examples**
46+ - [ Awesome example #0 ] ( examples/ sqlite3x-aex-0.md)
47+ - [ Awesome example #1 ] ( examples/ sqlite3x-aex-1.md)
5148
5249- ### [ PostgreSQLx] ( about-postgresqlx.md )
5350 - [ PostgreSQLxTable] ( about-table.md )
5451
5552- ### [ AbstractColumn] ( about-column.md )
5653
57- - ### [ SearchCondition] ( searchcondition- about.md)
54+ - ### [ SearchCondition] ( about-searchcondition .md )
5855
5956- ### [ Project Showcase] ( sqllex-showcase.md )
60- - [ Vaccine Update System] ( sqllex-showcase.md#vaccine-update-systemhttpsdeepnotecomabidvaccine-update-dashboard-gybicp-ftaydgmjimofj0w-- by-kingabzpro )
61- - [ Sqllex for Data Science Using Pandas] ( sqllex-showcase.md#sqllex-for-data-science-using-pandashttpsdeepnotecomabidsqllex-simple-and-faster-7wxrco0hrxaqvaixo8qjbq- by-kingabpro )
57+ - [ Vaccine Update System] ( sqllex-showcase.md#vaccine-update-systemcase-vsu-src- by-kingabzprokingabzpro )
58+ - [ Sqllex for Data Science Using Pandas] ( sqllex-showcase.md#sqllex-for-data-science-using-pandascase-dsup-src- by-kingabzprokingabzpro )
6259 - [ Add your own project at this list] ( https://github.com/v1a0/sqllex/edit/main/docs/sqllex-showcase.md )
60+
61+
62+ ---
63+
64+ ## How does this work?
65+
66+ Basic idea of sqllex as any ORM is to give user an interface to interact with a database as abstract object.
67+
68+ ``` markdown
69+ ┌───────────────────────────────────────────┐
70+ │ DATABASE │
71+ │ ┌───────────────────────────────────┐ │
72+ │ │ TABLE │ │
73+ │ │ ┌───────────────────────────┐ │ │
74+ │ │ │ COLUMN │ │ │
75+ │ │ │ ┌───────────────────┐ │ │ │
76+ │ │ │ │ DATA │ │ │ │
77+ │ │ │ └───────────────────┘ │ │ │
78+ │ │ └───────────────────────────┘ │ │
79+ │ │ │ │
80+ │ └───────────────────────────────────┘ │
81+ └───────────────────────────────────────────┘
82+ ```
83+
84+ Imagine you have a database called ` 'server.db' ` with only one table inside named ` 'users' ` ,
85+ this table has 3 columns ` 'id' ` , ` 'name' ` and ` 'age' ` (so as a pic down below)
86+
87+
88+ ``` markdown
89+ ┌───────────────────────────────────────────┐
90+ │ DATABASE 'server.db' │
91+ │ ┌───────────────────────────────────┐ │
92+ │ │ TABLE 'users' │ │
93+ │ │ ┌───────────────────────────┐ │ │
94+ │ │ │ COLUMN 'id' │ │ │
95+ │ │ │ ┌───────────────────┐ │ │ │
96+ │ │ │ │ INTEGER DATA │ │ │ │
97+ │ │ │ └───────────────────┘ │ │ │
98+ │ │ └───────────────────────────┘ │ │
99+ │ │ ┌───────────────────────────┐ │ │
100+ │ │ │ COLUMN 'name' │ │ │
101+ │ │ │ ┌───────────────────┐ │ │ │
102+ │ │ │ │ TEXT DATA │ │ │ │
103+ │ │ │ └───────────────────┘ │ │ │
104+ │ │ └───────────────────────────┘ │ │
105+ │ │ ┌───────────────────────────┐ │ │
106+ │ │ │ COLUMN 'age' │ │ │
107+ │ │ │ ┌───────────────────┐ │ │ │
108+ │ │ │ │ INTEGER DATA │ │ │ │
109+ │ │ │ └───────────────────┘ │ │ │
110+ │ │ └───────────────────────────┘ │ │
111+ │ └───────────────────────────────────┘ │
112+ └───────────────────────────────────────────┘
113+ ```
114+
115+ With the sqllex you can interact with this database in the craziest way
116+
117+ ``` python
118+ # Import necessary modules
119+ from sqllex.classes import SQLite3x
120+ from sqllex.constants.sqlite import *
121+
122+ # Database
123+ db = SQLite3x(' server.db' )
124+
125+ # Create this table
126+ db.create_table(
127+ ' users' ,
128+ {
129+ ' id' : INTEGER ,
130+ ' name' : TEXT ,
131+ ' age' : INTEGER
132+ },
133+ IF_NOT_EXIST = True
134+ )
135+
136+ table_users = db[' users' ]
137+ # table_users = db.get_table('users') <-- the same
138+
139+ # add one user
140+ table_users.insert(1 , ' Sqllex' , 33 )
141+
142+ # add 3 more
143+ table_users.insertmany(
144+ (2 , ' Phizilion' , 22 ),
145+ (3 , ' kingabzpro' , 44 ),
146+ (4 , ' asadafasab' , 55 )
147+ )
148+
149+ print (table_users.select_all()) # [(1, 'Sqllex', 33), (2, 'Phizilion', 22), (3, 'kingabzpro', 44), (4, 'asadafasab', 55)]
150+
151+ # Get column age as object
152+ column_age = table_users[' age' ]
153+
154+ print (
155+ table_users.select(
156+ WHERE = (column_age > 40 )
157+ )
158+ ) # [(3, 'kingabzpro', 44), (4, 'asadafasab', 55)]
159+
160+
161+ column_name = table_users[' name' ]
162+
163+
164+ print (
165+ table_users.select(
166+ WHERE = (column_age > 40 ) & (column_name | LIKE | ' kin%' )
167+ )
168+ ) # [(3, 'kingabzpro', 44)]
169+
170+ ```
0 commit comments