agate-sql Documentation

Similar documents
git-pr Release dev2+ng5b0396a

Sensor-fusion Demo Documentation

utidylib Documentation Release 0.4

PyCon APAC 2014 Documentation

X Generic Event Extension. Peter Hutterer

sensor-documentation Documentation

mp3fm Documentation Release Akshit Agarwal

Tailor Documentation. Release 0.1. Derek Stegelman, Garrett Pennington, and Jon Faustman

inflection Documentation

deepatari Documentation

BME280 Documentation. Release Richard Hull

XStatic Documentation

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Elegans Documentation

twstock Documentation

Dellve CuDNN Documentation

Feed Cache for Umbraco Version 2.0

retask Documentation Release 1.0 Kushal Das

disspcap Documentation

Statsd Metrics Documentation

dublincore Documentation

Instagram PHP Documentation

delegator Documentation

Daedalus Documentation

jumpssh Documentation

Piexif Documentation. Release 1.0.X. hmatoba

Imagination Documentation

puppet-diamond Documentation

CuteFlow-V4 Documentation

Industries Package. TARMS Inc.

Testworks User Guide. Release 1.0. Dylan Hackers

MCAFEE THREAT INTELLIGENCE EXCHANGE RESILIENT THREAT SERVICE INTEGRATION GUIDE V1.0

XEP-0099: IQ Query Action Protocol

Piexif Documentation. Release 1.0.X. hmatoba

OPi.GPIO Documentation

MatPlotTheme Documentation

Django Mail Queue Documentation

TWO-FACTOR AUTHENTICATION Version 1.1.0

abstar Documentation Release Bryan Briney

Firebase PHP SDK. Release

RTI Connext DDS Core Libraries

Asthma Eliminator MicroMedic Competition Entry

Open Source Used In Cisco Configuration Professional for Catalyst 1.0

invenio-formatter Documentation

iwrite technical manual iwrite authors and contributors Revision: 0.00 (Draft/WIP)

Inptools Manual. Steffen Macke

aiounittest Documentation

LANDISVIEW Beta v1.0-user Guide

Spotter Documentation Version 0.5, Released 4/12/2010

pydocstyle Documentation

josync Documentation Release 1.0 Joel Goop and Jonas Einarsson

Java Relying Party API v1.0 Programmer s Guide

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Imagination Documentation

Transparency & Consent Framework

KEMP Driver for Red Hat OpenStack. KEMP LBaaS Red Hat OpenStack Driver. Installation Guide

Simba Cassandra ODBC Driver with SQL Connector

HTNG Web Services Product Specification. Version 2014A

Dependency Injection Container Documentation

docxtemplater Documentation

SopaJS JavaScript library package

mqtt-broker Documentation

NDIS Implementation Guide

XEP-0044: Full Namespace Support for XML Streams

PHP-FCM Documentation

Folder Poll General User s Guide

clipbit Release 0.1 David Fraser

Transparency & Consent Framework

The XIM Transport Specification

Upgrading BankLink Books

XEP-0087: Stream Initiation

Quality of Service (QOS) With Tintri VM-Aware Storage

XEP-0363: HTTP File Upload

XEP-0104: HTTP Scheme for URL Data

MEAS HTU21D PERIPHERAL MODULE

HTNG Web Services Product Specification. Version 2011A

XEP-0399: Client Key Support

User Guide. Calibrated Software, Inc.

webbot Documentation Release Natesh M Bhat

Additional License Authorizations for HPE OneView for Microsoft Azure Log Analytics

Epic. Epic Systems. Deployment Guide

ExaFMM. Fast multipole method software aiming for exascale systems. User's Manual. Rio Yokota, L. A. Barba. November Revision 1

LoadMaster Clustering

XTEST Extension Library

ProFont began life as a better version of Monaco 9 which is especially good for programmers. It was created circa 1987 by Andrew Welch.

Colgate, WI

Black Mamba Documentation

Simba ODBC Driver with SQL Connector for Salesforce

Guest Book. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Tenable Hardware Appliance Upgrade Guide

Bluetooth Low Energy in C++ for nrfx Microcontrollers

Migration Tool. Migration Tool (Beta) Technical Note

SWTP 6800 Simulator Usage 27-Mar-2012

HCP Chargeback Collector Documentation

Preprocessing of fmri data

Object Identity Package. TARMS Inc.

LANDISVIEW User Guide

youtube-dl-api-server Release 0.3

XEP-0333: Chat Markers

SW MAPS TEMPLATE BUILDER. User s Manual

Transcription:

agate-sql Documentation Release 0.5.3 (beta) Christopher Groskopf Aug 10, 2017

Contents 1 Install 3 2 Usage 5 3 API 7 3.1 Authors.................................................. 8 3.2 Changelog................................................ 8 3.3 License.................................................. 10 3.4 Indices and tables............................................ 10 i

ii

agate-sql Documentation, Release 0.5.3 (beta) agate-sql adds SQL read/write support to agate. Important links: agate http://agate.rtfd.org Documentation: http://agate-sql.rtfd.org Repository: https://github.com/wireservice/agate-sql Issues: https://github.com/wireservice/agate-sql/issues Contents 1

agate-sql Documentation, Release 0.5.3 (beta) 2 Contents

CHAPTER 1 Install To install: pip install agate-sql For details on development or supported platforms see the agate documentation. Warning: You ll need to have the correct sqlalchemy drivers installed for whatever database you plan to access. For instance, in order to read/write tables in a Postgres database, you ll also need to pip install psycopg2. 3

agate-sql Documentation, Release 0.5.3 (beta) 4 Chapter 1. Install

CHAPTER 2 Usage agate-sql uses a monkey patching pattern to add SQL support to all agate.table instances. import agate import agatesql Importing agatesql attaches new methods to agate.table. For example, to import a table named doctors from a local postgresql database named hospitals you will use from_sql(): new_table = agate.table.from_sql('postgresql:///hospitals', 'doctors') To save this table back to the database: new_table.to_sql('postgresql:///hospitals', 'doctors') The first argument to either function can be any valid sqlalchemy connection string. The second argument must be a database name. (Arbitrary SQL queries are not supported.) That s all there is to it. 5

agate-sql Documentation, Release 0.5.3 (beta) 6 Chapter 2. Usage

CHAPTER 3 API agatesql.table.from_sql(cls, connection_or_string, table_name) Create a new agate.table from a given SQL table. Types will be inferred from the database schema. Monkey patched as class method Table.from_sql(). Parameters connection_or_string An existing sqlalchemy connection or connection string. table_name The name of a table in the referenced database. agatesql.table.from_sql_query(self, query) Create an agate table from the results of a SQL query. Note that column data types will be inferred from the returned data, not the column types declared in SQL (if any). This is more flexible than from_sql() but could result in unexpected typing issues. Parameters query A SQL query to execute. agatesql.table.to_sql(self, connection_or_string, table_name, overwrite=false, create=true, create_if_not_exists=false, insert=true, prefixes=[], db_schema=none, constraints=true) Write this table to the given SQL database. Monkey patched as instance method Table.to_sql(). Parameters connection_or_string An existing sqlalchemy connection or a connection string. table_name The name of the SQL table to create. overwrite Drop any existing table with the same name before creating. create Create the table. create_if_not_exists When creating the table, don t fail if the table already exists. insert Insert table data. prefixes Add prefixes to the insert query. 7

agate-sql Documentation, Release 0.5.3 (beta) db_schema Create table in the specified database schema. :param constraints Generate constraints such as nullable for table columns. agatesql.table.to_sql_create_statement(self, table_name, dialect=none, db_schema=none, constraints=true) Generates a CREATE TABLE statement for this SQL table, but does not execute it. Parameters table_name The name of the SQL table to create. dialect The dialect of SQL to use for the table statement. db_schema Create table in the specified database schema. :param constraints Generate constraints such as nullable for table columns. agatesql.table.sql_query(self, query, table_name= agate ) Convert this agate table into an intermediate, in-memory sqlite table, run a query against it, and then return the results as a new agate table. Multiple queries may be separated with semicolons. Parameters query One SQL query, or multiple queries to be run consecutively separated with semicolons. table_name The name to use for the table in the queries, defaults to agate. Authors The following individuals have contributed code to agate-sql: Christopher Groskopf Adrian Klaver James McKinney Chris Keller git-clueless z2s8 Jake Zimmerman Changelog 0.5.3 Specify precision and scale for DECIMAL if the dialect is mssql, mysql or oracle. Set length of VARCHAR to 1 even if maximum length is 0 to satisfy MySQL. 8 Chapter 3. API

agate-sql Documentation, Release 0.5.3 (beta) 0.5.2 - April 28, 2017 Add create_if_not_exists flag to TableSQL.to_sql(). 0.5.1 - February 27, 2017 Add prefixes option to to_sql() to add expressions following the INSERT keyword, like OR IGNORE or OR REPLACE. Use TIMESTAMP instead of DATETIME for DateTime columns. 0.5.0 - December 23, 2016 VARCHAR columns are now generated with proper length constraints (unless explicilty disabled). Tables can now be created from query results using from_sql_query(). Add support for running queries directly on tables with sql_query(). When creating tables, NOT NULL constraints will be created by default. SQL create statements can now be generated without being executed with to_sql_create_statement() 0.4.0 - December 19, 2016 Modified example.py so it no longer depends on Postgres. It is no longer necessary to run agatesql.patch() after importing agatesql. Upgrade required agate to 1.5.0. 0.3.0 - November 5, 2015 Add overwrite flag to TableSQL.to_sql(). Removed Python 2.6 support. Updated agate dependency to version 1.1.0. Additional SQL types are now supported. (#4, #10) 0.2.0 - October 22, 2015 Add explicit patch function. 0.1.0 - September 22, 2015 Initial version. 3.2. Changelog 9

agate-sql Documentation, Release 0.5.3 (beta) License The MIT License Copyright (c) 2017 Christopher Groskopf and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software ), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PAR- TICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT- WARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Indices and tables genindex modindex search 10 Chapter 3. API

Index F from_sql() (in module agatesql.table), 7 from_sql_query() (in module agatesql.table), 7 S sql_query() (in module agatesql.table), 8 T to_sql() (in module agatesql.table), 7 to_sql_create_statement() (in module agatesql.table), 8 11