示例#1
0
def test_functions_query(executor):
    run(
        executor, '''create function func1() returns int
                     language sql as $$select 1$$''')
    run(executor, 'create schema schema1')
    run(
        executor, '''create function schema1.func2() returns int
                     language sql as $$select 2$$''')

    run(
        executor, '''create function func3()
                     returns table(x int, y int) language sql
                     as $$select 1, 2 from generate_series(1,5)$$;''')

    run(
        executor,
        '''create function func4(x int) returns setof int language sql
                     as $$select generate_series(1,5)$$;''')

    funcs = set(executor.functions())
    assert funcs >= set([
        FunctionMetadata('public', 'func1', None, [], [], 'integer', False,
                         False, False),
        FunctionMetadata('public', 'func3', ['x', 'y'], ['integer', 'integer'],
                         ['t', 't'], 'record', False, False, True),
        FunctionMetadata('public', 'func4', ('x', ),
                         ('integer', ), [], 'integer', False, False, True),
        FunctionMetadata('schema1', 'func2', None, [], [], 'integer', False,
                         False, False),
    ])
示例#2
0
def test_function_metadata_eq():
    f1 = FunctionMetadata('s', 'f', 'x int', 'int', False, False, False)
    f2 = FunctionMetadata('s', 'f', 'x int', 'int', False, False, False)
    f3 = FunctionMetadata('s', 'g', 'x int', 'int', False, False, False)
    assert f1 == f2
    assert f1 != f3
    assert not (f1 != f2)
    assert not (f1 == f3)
    assert hash(f1) == hash(f2)
    assert hash(f1) != hash(f3)
示例#3
0
def completer():

    import pgcli.pgcompleter as pgcompleter
    comp = pgcompleter.PGCompleter(smart_completion=True)

    schemata, tables, columns = [], [], []

    for schema, tbls in metadata['tables'].items():
        schemata.append(schema)

        for table, cols in tbls.items():
            tables.append((schema, table))
            columns.extend([(schema, table, col) for col in cols])

    functions = [
        FunctionMetadata(schema, *func_meta)
        for schema, funcs in metadata['functions'].items()
        for func_meta in funcs
    ]

    datatypes = [(schema, datatype)
                 for schema, datatypes in metadata['datatypes'].items()
                 for datatype in datatypes]

    comp.extend_schemata(schemata)
    comp.extend_relations(tables, kind='tables')
    comp.extend_columns(columns, kind='tables')
    comp.extend_functions(functions)
    comp.extend_datatypes(datatypes)
    comp.set_search_path(['public'])

    return comp
def completer():

    import pgcli.pgcompleter as pgcompleter
    comp = pgcompleter.PGCompleter(smart_completion=True)

    schemata = ['public']
    comp.extend_schemata(schemata)

    # tables
    tables, columns = [], []
    for table, cols in metadata['tables'].items():
        tables.append(('public', table))
        columns.extend([('public', table, col) for col in cols])

    comp.extend_relations(tables, kind='tables')
    comp.extend_columns(columns, kind='tables')

    # views
    views, columns = [], []
    for view, cols in metadata['views'].items():
        views.append(('public', view))
        columns.extend([('public', view, col) for col in cols])

    comp.extend_relations(views, kind='views')
    comp.extend_columns(columns, kind='views')

    # functions
    functions = [
        FunctionMetadata('public', *func_meta)
        for func_meta in metadata['functions']
    ]
    comp.extend_functions(functions)

    # types
    datatypes = [('public', typ) for typ in metadata['datatypes']]
    comp.extend_datatypes(datatypes)

    comp.set_search_path(['public'])

    return comp