本文整理汇总了Python中ckan.model.meta.Session.connection方法的典型用法代码示例。如果您正苦于以下问题:Python Session.connection方法的具体用法?Python Session.connection怎么用?Python Session.connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ckan.model.meta.Session
的用法示例。
在下文中一共展示了Session.connection方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: migrate_extras
# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import connection [as 别名]
def migrate_extras():
conn = Session.connection()
statements = '''
ALTER TABLE datarequests ADD COLUMN extras text;
'''
conn.execute(statements)
Session.commit()
示例2: migrate_visibility
# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import connection [as 别名]
def migrate_visibility():
conn = Session.connection()
statements = '''
ALTER TABLE datarequests ADD COLUMN visibility integer;
'''
conn.execute(statements)
Session.commit()
示例3: GetRecords
# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import connection [as 别名]
def GetRecords(self, req):
resp = etree.Element(ntag("csw:GetRecordsResponse"), nsmap=namespaces)
etree.SubElement(resp, ntag("csw:SearchStatus"), timestamp=datetime.utcnow().isoformat())
cursor = Session.connection()
q = Session.query(distinct(HarvestObject.guid)) \
.join(Package) \
.join(HarvestSource) \
.filter(HarvestObject.current==True) \
.filter(Package.state==u'active') \
.filter(or_(HarvestSource.type=='gemini-single', \
HarvestSource.type=='gemini-waf', \
HarvestSource.type=='csw'))
### TODO Parse query instead of stupidly just returning whatever we like
startPosition = req["startPosition"] if req["startPosition"] > 0 else 1
maxRecords = req["maxRecords"] if req["maxRecords"] > 0 else 10
rset = q.offset(startPosition-1).limit(maxRecords)
total = q.count()
attrs = {
"numberOfRecordsMatched": total,
"elementSet": req["elementSetName"], # we lie here. it's always really "full"
}
if req["resultType"] == "results":
returned = rset.count()
attrs["numberOfRecordsReturned"] = returned
if (total-startPosition-1) > returned:
attrs["nextRecord"] = startPosition + returned
else:
attrs["nextRecord"] = 0
else:
attrs["numberOfRecordsReturned"] = 0
attrs = dict((k, unicode(v)) for k,v in attrs.items())
results = etree.SubElement(resp, ntag("csw:SearchResults"), **attrs)
if req["resultType"] == "results":
for guid, in Session.execute(rset):
doc = Session.query(HarvestObject) \
.join(Package) \
.filter(HarvestObject.guid==guid) \
.filter(HarvestObject.current==True) \
.filter(Package.state==u'active') \
.first()
try:
record = etree.parse(StringIO(doc.content.encode("utf-8")))
results.append(record.getroot())
except:
log.error("exception parsing document %s:\n%s", doc.id, traceback.format_exc())
raise
data = self._render_xml(resp)
log.info('GetRecords response: %r', truncate(data, LOG_XML_LENGTH))
return data
示例4: migrate_to_v0_6
# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import connection [as 别名]
def migrate_to_v0_6():
conn = Session.connection()
statement = """
ALTER TABLE external_catalog
ADD COLUMN create_as_private BOOLEAN NOT NULL DEFAULT FALSE;
"""
conn.execute(statement)
Session.commit()
示例5: migrate_to_v0_4
# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import connection [as 别名]
def migrate_to_v0_4():
conn = Session.connection()
statement = """
ALTER TABLE external_catalog
ADD COLUMN ext_org_id text;
"""
conn.execute(statement)
Session.commit()
示例6: migrate_to_v0_3
# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import connection [as 别名]
def migrate_to_v0_3():
conn = Session.connection()
statement = """
ALTER TABLE external_catalog
ADD COLUMN last_updated timestamp,
ADD COLUMN status smallint not null default 0;
"""
conn.execute(statement)
Session.commit()
示例7: migrate_v3
# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import connection [as 别名]
def migrate_v3():
log.debug("Migrating harvest tables to v3. This may take a while...")
conn = Session.connection()
statement = """CREATE TABLE harvest_object_extra (
id text NOT NULL,
harvest_object_id text,
"key" text,
"value" text
);
ALTER TABLE harvest_object
ADD COLUMN import_started timestamp without time zone,
ADD COLUMN import_finished timestamp without time zone,
ADD COLUMN "state" text,
ADD COLUMN "report_status" text;
ALTER TABLE harvest_source
ADD COLUMN frequency text,
ADD COLUMN next_run timestamp without time zone;
ALTER TABLE harvest_job
ADD COLUMN finished timestamp without time zone;
ALTER TABLE harvest_object_extra
ADD CONSTRAINT harvest_object_extra_pkey PRIMARY KEY (id);
ALTER TABLE harvest_object_extra
ADD CONSTRAINT harvest_object_extra_harvest_object_id_fkey FOREIGN KEY (harvest_object_id) REFERENCES harvest_object(id);
UPDATE harvest_object set state = 'COMPLETE' where package_id is not null;
UPDATE harvest_object set state = 'ERROR' where package_id is null;
UPDATE harvest_object set retry_times = 0;
UPDATE harvest_object set report_status = 'updated' where package_id is not null;
UPDATE harvest_object set report_status = 'errored' where package_id is null;
UPDATE harvest_source set frequency = 'MANUAL';
ALTER TABLE harvest_object DROP CONSTRAINT harvest_object_package_id_fkey;
ALTER TABLE harvest_object
ADD CONSTRAINT harvest_object_package_id_fkey FOREIGN KEY (package_id) REFERENCES package(id) DEFERRABLE;
ALTER TABLE harvest_object_error
ADD COLUMN line integer;
"""
conn.execute(statement)
Session.commit()
log.info("Harvest tables migrated to v3")
示例8: migrate_v2
# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import connection [as 别名]
def migrate_v2():
log.debug("Migrating harvest tables to v2. This may take a while...")
conn = Session.connection()
statements = """
ALTER TABLE harvest_source ADD COLUMN title text;
ALTER TABLE harvest_object ADD COLUMN current boolean;
ALTER TABLE harvest_object ADD COLUMN harvest_source_id text;
ALTER TABLE harvest_object ADD CONSTRAINT harvest_object_harvest_source_id_fkey FOREIGN KEY (harvest_source_id) REFERENCES harvest_source(id);
UPDATE harvest_object o SET harvest_source_id = j.source_id FROM harvest_job j WHERE o.harvest_job_id = j.id;
"""
conn.execute(statements)
# Flag current harvest_objects
guids = (
Session.query(distinct(HarvestObject.guid))
.join(Package)
.filter(HarvestObject.package != None)
.filter(Package.state == u"active")
)
update_statement = """
UPDATE harvest_object
SET current = TRUE
WHERE id = (
SELECT o.id
FROM harvest_object o JOIN package p ON p.id = o.package_id
WHERE o.package_id IS NOT null AND p.state = 'active'
AND o.guid = '%s'
ORDER BY metadata_modified_date DESC, fetch_finished DESC, gathered DESC
LIMIT 1)
"""
for guid in guids:
conn.execute(update_statement % guid)
conn.execute("UPDATE harvest_object SET current = FALSE WHERE current IS NOT TRUE")
Session.commit()
log.info("Harvest tables migrated to v2")