Giter Site home page Giter Site logo

hasa1002 / pydapper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zschumacher/pydapper

0.0 0.0 0.0 363 KB

a pure python port of the NuGet library dapper

Home Page: https://pydapper.readthedocs.io/en/latest/

License: MIT License

Python 98.62% Makefile 1.38%

pydapper's Introduction

PyPI version Documentation Status codecov License: MIT Code style: black Imports: isort PyPI - Python Version

pydapper

A pure python library inspired by the NuGet library dapper.

pydapper is built on top of the dbapi 2.0 spec to provide more convenient methods for working with databases in python.

Help

See the documentation for more details.

Installation

It is recommended to only install the database apis you need for your use case. Example below is for psycopg2!

pip

pip install pydapper[psycopg2]

poetry

poetry add pydapper -E psycopg2

Never write this again...

from psycopg2 import connect

@dataclass
class Task:
    id: int
    description: str
    due_date: datetime.date

with connect("postgresql://pydapper:pydapper@localhost/pydapper") as conn:
    with conn.cursor() as cursor:
        cursor.execute("select id, description, due_date from task")
        headers = [i[0] for i in cursor.description]
        data = cursor.fetchall()

list_data = [Task(**dict(zip(headers, row))) for row in data]

Instead, write...

from dataclasses import dataclass
import datetime

import pydapper


@dataclass
class Task:
    id: int
    description: str
    due_date: datetime.date

    
with pydapper.connect("postgresql+psycopg2://pydapper:pydapper@locahost/pydapper") as commands:
    tasks = commands.query("select id, description, due_date from task;", model=Task)

(This script is complete, it should run "as is")

Buy me a coffee

If you find this project useful, consider buying me a coffee!

Buy Me A Coffee

pydapper's People

Contributors

zschumacher avatar bowiec avatar enewnham avatar idumancic avatar otosky avatar troyswanson 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.