Skip to content
Permalink
Browse files

Method for storing other datatypes is implemented in DbStorage

Method for storing other datatypes is implemented in DbStorage. Until now, it was implemented in both SQLiteStorage and PgStorage and the two methods weere almost identical.
  • Loading branch information...
janpisl committed Jul 4, 2018
1 parent 956b37b commit 341f8a8eb8d99663e15796e373c5bf78fc9364a6
Showing with 49 additions and 84 deletions.
  1. +48 −0 pywps/inout/storage/db/__init__.py
  2. +0 −45 pywps/inout/storage/db/pg.py
  3. +1 −39 pywps/inout/storage/db/sqlite.py
@@ -103,3 +103,51 @@ def store(self, output):
# returns value for database storage defined in the STORE_TYPE class,
# name of the output file and a reference
return (STORE_TYPE.DB, output.file, url)


def store_other_output(self, file_name, identifier, uuid):

from pywps import configuration as config
import sqlalchemy
from sqlalchemy import Column, Integer, String, LargeBinary, DateTime, func, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

base = declarative_base()

if isinstance(self, sqlite.SQLiteStorage):
engine = sqlalchemy.create_engine("sqlite:///{}".format(self.dblocation))
elif isinstance(self, pg.PgStorage):
engine = sqlalchemy.create_engine('postgresql://{}:{}@{}:{}/{}'.format(
self.dbname,self.password,self.host,self.port,self.user
)
)

# Create table
class Other_output(base):
__tablename__ = identifier
if isinstance(self, pg.PgStorage):
__table_args__ = {'schema' : self.schema_name}


primary_key = Column(Integer, primary_key=True)
uuid = Column(String(64))
data = Column(LargeBinary)
timestamp = Column(DateTime(timezone=True), server_default=func.now())

Session = sessionmaker(engine)
session = Session()

base.metadata.create_all(engine)

# Open file as binary
with open(file_name, "rb") as data:
out = data.read()

# Add data to table
output = Other_output(uuid=uuid, data=out)
session.add(output)
session.commit()


return identifier
@@ -68,48 +68,3 @@ def store_raster_output(self, file_name, identifier):


return identifier


def store_other_output(self, file_name, identifier, uuid):

from pywps import configuration as config
import sqlalchemy
from sqlalchemy import Column, Integer, String, LargeBinary, DateTime, func, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

base = declarative_base()

engine = sqlalchemy.create_engine('postgresql://{}:{}@{}:{}/{}'.format(
self.dbname,self.password,self.host,self.port,self.user
)
)

# Create table
class Other_output(base):
__tablename__ = identifier
__table_args__ = {'schema' : self.schema_name}

primary_key = Column(Integer, primary_key=True)
uuid = Column(String(64))
data = Column(LargeBinary)
timestamp = Column(DateTime(timezone=True), server_default=func.now())

Session = sessionmaker(engine)
session = Session()

base.metadata.create_all(engine)

# Open file as binary
with open(file_name, "rb") as data:
out = data.read()

# Add data to table
output = Other_output(uuid=uuid, data=out)
session.add(output)
session.commit()


return identifier


@@ -5,7 +5,7 @@

import logging
from pywps import configuration as config
from .. import DbStorageAbstract, STORE_TYPE
from .. import STORE_TYPE
from pywps.inout.formats import DATA_TYPE
from pywps.exceptions import NoApplicableCode
from . import DbStorage
@@ -59,41 +59,3 @@ def store_raster_output(self, file_name, identifier):

# returns process identifier (defined within the process)
return identifier

def store_other_output(self, file_name, identifier, uuid):

from pywps import configuration as config
import sqlalchemy
from sqlalchemy import Column, Integer, String, LargeBinary, DateTime, func, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

base = declarative_base()

engine = sqlalchemy.create_engine("sqlite:///{}".format(self.dblocation))

# Create table
class Other_output(base):
__tablename__ = identifier

primary_key = Column(Integer, primary_key=True)
uuid = Column(String(64))
data = Column(LargeBinary)
timestamp = Column(DateTime(timezone=True), server_default=func.now())

Session = sessionmaker(engine)
session = Session()

base.metadata.create_all(engine)

# Open file as binary
with open(file_name, "rb") as data:
out = data.read()

# Add data to table
output = Other_output(uuid=uuid, data=out)
session.add(output)
session.commit()


return identifier

0 comments on commit 341f8a8

Please sign in to comment.
You can’t perform that action at this time.