美文网首页
python sqlalchemy

python sqlalchemy

作者: hehehehe | 来源:发表于2022-03-01 18:00 被阅读0次
from sqlalchemy import func
from sqlalchemy.types import UserDefinedType

class Geometry(UserDefinedType):
    def get_col_spec(self):
        return "GEOMETRY"

    def bind_expression(self, bindvalue):
        return func.ST_GeomFromText(bindvalue, 4326, type_=self)

    def column_expression(self, col):
        return func.ST_AsText(col, type_=self)

from urllib.parse import quote_plus

from sqlalchemy import Column, Integer, Float, String, ForeignKey, create_engine, DateTime
from sqlalchemy.orm import declarative_base, sessionmaker
from pyorm.typehandler.geom_handler import Geometry

# declarative base class
Base = declarative_base()

# an example mapping using the base
class PoiHnEditTest(Base):
    __tablename__ = 'poi_hn_edit_test'

    hn_id = Column(String, primary_key=True)
    address = Column(String, nullable=False)
    longitude = Column(Float, nullable=False)
    latitude = Column(Float, nullable=False)
    geom = Column(Geometry, nullable=False)

相关文章

网友评论

      本文标题:python sqlalchemy

      本文链接:https://www.haomeiwen.com/subject/hbzdrrtx.html