예제 #1
0
def test_create_from_datashape():
    engine = sa.create_engine('sqlite:///:memory:')
    ds = dshape('''{bank: var * {name: string, amount: int},
                    points: var * {x: int, y: int}}''')
    engine = create_from_datashape(engine, ds)

    assert discover(engine) == ds
def test_csv_postgres_load(tbl):
    engine = sa.create_engine(url)

    if engine.has_table(tbl):
        metadata = sa.MetaData()
        metadata.reflect(engine)
        t = metadata.tables[tbl]
        t.drop(engine)

    create_from_datashape(engine, dshape("{%s: %s}" % (tbl, ds)))
    metadata = sa.MetaData()
    metadata.reflect(engine)
    conn = engine.raw_connection()

    cursor = conn.cursor()
    full_path = os.path.abspath(file_name)
    load = """copy {0} from '{1}'(FORMAT CSV, DELIMITER ',', NULL '');""".format(tbl, full_path)
    cursor.execute(load)
    conn.commit()