GithubHelp home page GithubHelp logo

poshodev / loaf Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 117 KB

🍞 Effortless SQL server and proceduresβ€”plus other utilitiesβ€”for people who really hate cursors!

Home Page: https://pypi.org/project/Loaf/

Python 100.00%
mysql python database db bread loaf sql mariadb

loaf's Introduction

🍞 Loaf

So bland yet so good!β„’

Effortlessly access your SQL servers and procedures, plus some other utilities.

Install

$ pip install loaf

Examples

Importing Into Your Project

from loaf import Loaf

Setting Up Credentials

# Setup your credentials with a single line.
loaf = Loaf(port=6969, db="pizzeria")
# Or load your credentials from a file.
loaf = Loaf(file="creds.ini")
# Or use a local SQLite file instead.
loaf = Loaf(file="pizzeria.db")

Executing Queries

# Make queries easily.
toppings = loaf.query("SELECT * from toppings")
# Load your quieries directly from files.
clients = loaf.query(file="getHappyClients.sql")
# Prevent disasters by executing multiple queries.
pepperoni_id, client_name = loaf.multi([
    "SELECT id FROM toppings WHERE name='Pepperoni'",
    "SELECT name FROM clients WHERE id=6"
])

Printing

# Display info using built-in tables!
loaf.print(pepperoni_id)
loaf.print(client_name)
loaf.print(toppings)
┏━━━━┓
┃ id ┃
┑━━━━┩
β”‚ 1  β”‚
β””β”€β”€β”€β”€β”˜
┏━━━━━━━━━━━┓
┃ name      ┃
┑━━━━━━━━━━━┩
β”‚ 'Alfonso' β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
┏━━━━┳━━━━━━━━━━━━━┳━━━━━━━┓
┃ id ┃ name        ┃ price ┃
┑━━━━╇━━━━━━━━━━━━━╇━━━━━━━┩
β”‚ 1  β”‚ 'Pepperoni' β”‚ 1.49  β”‚
β”‚ 2  β”‚ 'Mushrooms' β”‚ 1.99  β”‚
β”‚ 3  β”‚ 'Onions'    β”‚ 0.99  β”‚
β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜

Data Manipulation

# Manipulate your data with dictionaries, as God intended.
for topping in toppings:
    print(topping['name'])
Pepperoni
Mushrooms
Onions

Utilities

# Not lazy enough? Try some of the pre-built queires.
# Equivalent of: SELECT name FROM client WHERE name='Marco' LIMIT 1
result = loaf.select("name", "clients", "name='Marco'", limit=1)
# Get all values from a table.
result = loaf.all("toppings")
# Got stored procedures? No problemo!
result = loaf.call("ProcedureFindClient", 1)

⚠️ Syntax for the package has changed heavily since version 0.2.0, if your project depends on Loaf and is using an inferior version, I heavily suggest that you use the previous stable version:

$ pip install loaf==0.1.30

loaf's People

Contributors

poshodev avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  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.