# Path: odpw/core/model.py
# class Portal(Base):
# class PortalSnapshot(Base):
# class Serializable(object):
# class PortalSnapshotDynamicity(Base,Serializable):
# class PortalSnapshotQuality(Base):
# class Dataset(Base):
# class DatasetData(Base):
# class DatasetQuality(Base):
# class MetaResource(Base):
# class ResourceInfo(Base):
# class ResourceCrawlLog(Base):
# class ResourceHistory(Base):
# class ResourceFreshness(Base):
# class FormatDist(Base):
#     def snapshot_count(self):
#     def snapshot_count(cls):
#     def first_snapshot(self):
#     def first_snapshot(cls):
#     def last_snapshot(self):
#     def last_snapshot(cls):
#     def datasetcount(self):
#     def datasetcount(cls):
#     def resourcecount(self):
#     def resourcecount(cls):
#     def __repr__(self):
#     def fetchtime(self):
#     def __repr__(self):
#     def to_dict(self):
#     def dyratio(self):
#     def adddelratio(self):
#     def addRatio(self):
#     def delRatio(self):
#     def updatedRatio(self):
#     def staticRatio(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def info(cls):
#     def __repr__(self):


import sqlalchemy
from sqlalchemy import *
from sqlalchemy.orm import Query
from sqlalchemy.schema import DDLElement
from sqlalchemy.sql import table
from sqlalchemy.ext import compiler
from odpw.core.model import Base
from psycopg2.extensions import adapt as sqlescape
    params = {}
    for k,v in comp.params.iteritems():
        if isinstance(v, unicode):
            v = v.encode(enc)
        params[k] = sqlescape(v)
    return (comp.string.encode(enc) % params).decode(enc)

@compiler.compiles(CreateView)
def compile(element, compiler, **kw):
    return "CREATE MATERIALIZED VIEW %s AS %s" % (element.name, compile_query(element.selectable))

@compiler.compiles(DropView)
def compile(element, compiler, **kw):
    return "DROP MATERIALIZED VIEW IF EXISTS %s" % (element.name)

def view(name, metadata, selectable):
    t = table(name)

    orig=selectable
    if isinstance(selectable, Query):
        selectable = selectable.subquery()

    for c in selectable.c:
        c._make_proxy(t)

    CreateView(name, orig).execute_at('after-create', metadata)
    DropView(name).execute_at('before-drop', metadata)
    return t



# Path: odpw/core/model.py
# class Portal(Base):
# class PortalSnapshot(Base):
# class Serializable(object):
# class PortalSnapshotDynamicity(Base,Serializable):
# class PortalSnapshotQuality(Base):
# class Dataset(Base):
# class DatasetData(Base):
# class DatasetQuality(Base):
# class MetaResource(Base):
# class ResourceInfo(Base):
# class ResourceCrawlLog(Base):
# class ResourceHistory(Base):
# class ResourceFreshness(Base):
# class FormatDist(Base):
#     def snapshot_count(self):
#     def snapshot_count(cls):
#     def first_snapshot(self):
#     def first_snapshot(cls):
#     def last_snapshot(self):
#     def last_snapshot(cls):
#     def datasetcount(self):
#     def datasetcount(cls):
#     def resourcecount(self):
#     def resourcecount(cls):
#     def __repr__(self):
#     def fetchtime(self):
#     def __repr__(self):
#     def to_dict(self):
#     def dyratio(self):
#     def adddelratio(self):
#     def addRatio(self):
#     def delRatio(self):
#     def updatedRatio(self):
#     def staticRatio(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def info(cls):
#     def __repr__(self):


# Path: odpw/core/mat_views.py
import sqlalchemy
from sqlalchemy import *
from sqlalchemy.orm import Query
from sqlalchemy.schema import DDLElement
from sqlalchemy.sql import table
from sqlalchemy.ext import compiler
from odpw.core.model import Base
from psycopg2.extensions import adapt as sqlescape

    params = {}
    for k,v in comp.params.iteritems():
        if isinstance(v, unicode):
            v = v.encode(enc)
        params[k] = sqlescape(v)
    return (comp.string.encode(enc) % params).decode(enc)

@compiler.compiles(CreateView)
def compile(element, compiler, **kw):
    return "CREATE MATERIALIZED VIEW %s AS %s" % (element.name, compile_query(element.selectable))

@compiler.compiles(DropView)
def compile(element, compiler, **kw):
    return "DROP MATERIALIZED VIEW IF EXISTS %s" % (element.name)

def view(name, metadata, selectable):
    t = table(name)

    orig=selectable
    if isinstance(selectable, Query):
        selectable = selectable.subquery()

    for c in selectable.c:
        c._make_proxy(t)

    CreateView(name, orig).execute_at('after-create', metadata)
    DropView(name).execute_at('before-drop', metadata)
    return t



def withView(query, viewName, session, dbc, metadata=Base.metadata):