
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
This is a simple python mysql builder design to easiy query & get data from your mysql database
Hi! Wellcome to Mysql Builder, Using this library you can easily make your mysql query. Link: Goto Package link
pip install mysqlbuilder
Create logs folder in your project root.
mkdir logs
import the package in your project
from mysqlbuilder.Builder import Builder
obj = Builder('Your_database_name')
obj.select('*').from('your_table_name).where({'column1' : 'condition1', 'column2' : 'condition2'}).get().execute()
SELECT * FROM your_table_name WHERE column1 = 'condition1' AND column2 = 'condition2';
db_config = {
'host': 'localhost',
'user': 'root',
'password': '',
'database': 'Your_database_name',
}
obj = Builder(db_config)
Note You need to pass the database config in mentioned dictonary with same keyword.
obj.select('*')
You can also pass the column names as well
obj.select('id, name, age, mobile number')
You can use alias as well
obj.select('name as username')
Note You can use all of those mysql default command in select
obj.table('your_table_name')
set table alias
obj.table('your_table_name as table')
obj.where({'id': 1})
Note You have to use the python Dictionary in where condition
Basically orWhere as same as Where condition but the difference is it will place a "OR" in the condition
obj.orWhere({'si.is_delete': '0', 'si.is_create': '0'})
Basically there are three type of joining we are support right now
You do not have to pass any additional parameter, by default we will treat join as INNER JOIN
obj = Builder('Your_database_name').select('u.name as username, a.city as
user_city').table('users u').join('address a', 'u.address_id = a.id')
SELECT u.name as username, a.city as user_city FROM users u INNER JOIN address a ON u.address_id = a.id
You have to pass the left
as keyword in the last parameter in join method
obj = Builder('Your_database_name').select('u.name as username, a.city as
user_city').table('users u').join('address a', 'u.address_id = a.id', 'left')
SELECT u.name as username, a.city as user_city FROM users u LEFT JOIN address a ON u.address_id = a.id
You have to pass the right
as keyword in the last parameter in join method
obj = Builder('Your_database_name').select('u.name as username, a.city as
user_city').table('users u').join('address a', 'u.address_id = a.id', 'right')
SELECT u.name as username, a.city as user_city FROM users u RIGHT JOIN address a ON u.address_id = a.id
raw sql is given to write the custom query which you want to execute but not given to this library.
obj.table('your_table_name').select(*).raw_sql("date => '2023-07-23' AND date <= '2023-07-23'")
SELECT * FROM your_table_name WHERE date => '2023-07-23' AND date <= '2023-07-23'
obj.table('your_table_name').select(*).limit('100')
SELECT * FROM your_table_name limit 100
you can use the limit offset to query the limit
obj.table('your_table_name').select(*).limit(100,300)
SELECT * FROM your_table_name limit 100, 300
obj.table('your_table_name').select(*).orderBy('id', 'ASC')
SELECT * FROM your_table_name ORDER BY id ASC
obj.table('your_table_name').select(*).groupBy('name')
SELECT * FROM your_table_name GROUP BY name
obj.table('your_table_name').select(*).like('name', 'santu sarkar')
SELECT * FROM your_table_name where name like '%santu sarkar%'
This method is used to combine all of your query params & condition and together generate the sql
obj.table('your_table_name').select('id, name, state_id').get()
Note This comman do not produce any additional output but internally it's used to generate the sql
This method is the used to compile & execute the sql query and produce the output as an python dictionary format
obj.table('your_table_name').select('id, name, state_id').get().execute
This method is used to check the query as plain text
you can use this in print()
print(obj.compiled_query())
FAQs
This is a simple python mysql builder design to easiy query & get data from your mysql database
We found that mysqlbuilder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.