SHARE
TWEET

Untitled

a guest Mar 15th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Word(Base):
  2.         __tablename__ = 'word'
  3.         eng                 = Column(String(32),primary_key=True)
  4.         chinese             = Column(String(128))
  5.  
  6. word = Word(eng='art',chinese=[u'艺术',u'美术'])
  7. session.add(word)
  8. session.commit()
  9.    
  10. class Word(Base):
  11.     __tablename__ = "words"
  12.  
  13.     id = Column(Integer, primary_key=True)
  14.     eng = Column(String(32), unique=True)
  15.     chinese = relationship("Chinese", backref="eng")
  16.  
  17.     def __init__(self, eng, chinese):
  18.         self.eng = eng
  19.         self.chinese = map(Chinese, chinese)
  20.  
  21. class Chinese(Base):
  22.     __tablename__ = "chinese_words"
  23.  
  24.     word = Column(String(128), primary_key=True)
  25.     eng_id = Column(Integer, ForeignKey('words.id'), primary_key=True)
  26.  
  27.     def __init__(self, word):
  28.         self.word = word
  29.    
  30. class Json(TypeDecorator):
  31.  
  32.     impl = String
  33.  
  34.     def process_bind_param(self, value, dialect):
  35.         return json.dumps(value)
  36.  
  37.     def process_result_value(self, value, dialect):
  38.         return json.loads(value)
  39.  
  40. class Word(Base):
  41.     __tablename__ = "words"
  42.  
  43.     eng = Column(String(32), primary_key=True)
  44.     chinese = Column(Json(128))
  45.    
  46. ('art', u'艺术')
  47. ('art', u'美术')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top