Module pugsql

PugSQL is an anti-ORM that facilitates interacting with databases using SQL in files. A minimal usage example:

# create a module from sql files on disk
queries = pugsql.module('path/to/sql/files')

# connect to the database and use the sql queries as functions
queries.connect(connection_string)
queries.update_username(user_id=42, username='mcfunley')
Source code
"""
PugSQL is an anti-ORM that facilitates interacting with databases using SQL
in files. A minimal usage example:

    # create a module from sql files on disk
    queries = pugsql.module('path/to/sql/files')

    # connect to the database and use the sql queries as functions
    queries.connect(connection_string)
    queries.update_username(user_id=42, username='mcfunley')

"""
from . import compiler


__version__ = '0.2.4'


def module(sqlpath, encoding=None):
    """
    Compiles a set of SQL files in the directory specified by sqlpath, and
    returns a module. The module contains a function for each named query
    found in the files.

        # create a module from sql files on disk
        queries = pugsql.module('path/to/sql/files')

        # connect to the database and use the sql queries as functions
        queries.connect(connection_string)
        queries.update_username(user_id=42, username='mcfunley')
    """
    return compiler.Module(sqlpath, encoding=encoding)


__all__ = ['__version__', 'module',]

Sub-modules

pugsql.compiler

Code that processes SQL files and returns modules of database functions.

pugsql.context

Objects and methods used to keep track of positions in source files.

pugsql.exceptions

Exception types raised by PugSQL. PugSQL will also raise built-in exceptions when they're appropriate.

pugsql.lexer

Functions that take strings and yield streams or dicts of Token objects, keeping track of source location.

pugsql.parser

Code that consumes PugSQL-dialect sql strings and returns validated Statement objects.

pugsql.statement

Compiled SQL function objects.

Functions

def module(sqlpath, encoding=None)

Compiles a set of SQL files in the directory specified by sqlpath, and returns a module. The module contains a function for each named query found in the files.

# create a module from sql files on disk
queries = pugsql.module('path/to/sql/files')

# connect to the database and use the sql queries as functions
queries.connect(connection_string)
queries.update_username(user_id=42, username='mcfunley')
Source code
def module(sqlpath, encoding=None):
    """
    Compiles a set of SQL files in the directory specified by sqlpath, and
    returns a module. The module contains a function for each named query
    found in the files.

        # create a module from sql files on disk
        queries = pugsql.module('path/to/sql/files')

        # connect to the database and use the sql queries as functions
        queries.connect(connection_string)
        queries.update_username(user_id=42, username='mcfunley')
    """
    return compiler.Module(sqlpath, encoding=encoding)