本文整理汇总了Python中stetl.postgis.PostGIS.get_column_names方法的典型用法代码示例。如果您正苦于以下问题:Python PostGIS.get_column_names方法的具体用法?Python PostGIS.get_column_names怎么用?Python PostGIS.get_column_names使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stetl.postgis.PostGIS
的用法示例。
在下文中一共展示了PostGIS.get_column_names方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PostgresDbInput
# 需要导入模块: from stetl.postgis import PostGIS [as 别名]
# 或者: from stetl.postgis.PostGIS import get_column_names [as 别名]
class PostgresDbInput(SqlDbInput):
"""
Input by querying records from a Postgres database.
Input is a query, like SELECT * from mytable.
Output is zero or more records as record array (array of dict) or single record (dict).
produces=FORMAT.record_array (default) or FORMAT.record
"""
# Start attribute config meta
@Config(ptype=str, required=False, default='localhost')
def host(self):
"""
host name or host IP-address, defaults to 'localhost'
"""
pass
@Config(ptype=str, required=False, default='5432')
def port(self):
"""
port for host, defaults to `'5432'
"""
pass
@Config(ptype=str, required=False, default='postgres')
def user(self):
"""
User name, defaults to 'postgres'
"""
pass
@Config(ptype=str, required=False, default='postgres')
def password(self):
"""
User password, defaults to 'postgres'
"""
pass
@Config(ptype=str, required=False, default='public')
def schema(self):
"""
The postgres schema name, defaults to 'public'
"""
pass
# End attribute config meta
def __init__(self, configdict, section):
SqlDbInput.__init__(self, configdict, section, produces=[FORMAT.record_array, FORMAT.record])
self.db = None
def init(self):
# Connect only once to DB
log.info('Init: connect to DB')
self.db = PostGIS(self.cfg.get_dict())
self.db.connect()
# If no explicit column names given, get from DB meta info
self.columns = self.column_names
if self.column_names is None:
self.columns = self.db.get_column_names(self.cfg.get('table'), self.cfg.get('schema'))
def exit(self):
# Disconnect from DB when done
log.info('Exit: disconnect from DB')
self.db.disconnect()
def raw_query(self, query_str):
self.db.execute(query_str)
db_records = self.db.cursor.fetchall()
log.info('read recs: %d' % len(db_records))
return db_records