예제 #1
0
def test_simple_query(sqlite):
    _test_create_insert = ("-- name: create-some-table\n"
                           "-- testing insertion\n"
                           "CREATE TABLE foo (a, b, c);\n\n"
                           "-- name: insert-some-value\n"
                           "INSERT INTO foo (a, b, c) VALUES (1, 2, 3);\n")

    q = anosql.load_queries_from_string("sqlite", _test_create_insert)
    q.create_some_table(sqlite)
    q.insert_some_value(sqlite)
예제 #2
0
def test_parametrized_insert_named(sqlite):
    _test_create_insert = ("-- name: create-some-table\n"
                           "-- testing insertion\n"
                           "CREATE TABLE foo (a, b, c);\n\n"
                           "-- name: insert-some-value\n"
                           "INSERT INTO foo (a, b, c) VALUES (:a, :b, :c);\n\n"
                           "-- name: get-all-values\n"
                           "SELECT * FROM foo;\n")

    q = anosql.load_queries_from_string("sqlite", _test_create_insert)
    q.create_some_table(sqlite)
    q.insert_some_value(sqlite, c=12, b=11, a=10)
    assert q.get_all_values(sqlite) == [(10, 11, 12)]
예제 #3
0
def test_simple_query_pg(postgres):
    _queries = ("-- name: create-some-table!\n"
                "-- testing insertion\n"
                "CREATE TABLE foo (id serial primary key, a int, b int, c int);\n\n"
                "-- name: insert-some-value<!\n"
                "INSERT INTO foo (a, b, c) VALUES (1, 2, 3)\n\n"
                "-- name: get-all-values\n"
                "SELECT a, b, c FROM foo;\n")

    q = anosql.load_queries_from_string("postgres", _queries)

    q.create_some_table(postgres)
    q.insert_some_value_auto(postgres)

    assert q.get_all_values(postgres) == [(1, 2, 3)]
예제 #4
0
def test_parameterized_select_named_pg(postgres):
    _queries = ("-- name: create-some-table!\n"
                "-- testing insertion\n"
                "CREATE TABLE foo (id serial primary key, a int, b int, c int);\n\n"
                "-- name: insert-some-value!\n"
                "INSERT INTO foo (a, b, c) VALUES (1, 2, 3)\n\n"
                "-- name: get-all-values\n"
                "SELECT a, b, c FROM foo WHERE a = %(a)s;\n")

    q = anosql.load_queries_from_string("postgres", _queries)

    q.create_some_table(postgres)
    q.insert_some_value(postgres)

    assert q.get_all_values(postgres, a=1) == [(1, 2, 3)]