Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d8f2153
Showing
7 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
*.py[co] | ||
|
||
# Packages | ||
*.egg | ||
*.egg-info | ||
dist | ||
build | ||
eggs | ||
parts | ||
bin | ||
var | ||
sdist | ||
develop-eggs | ||
.installed.cfg | ||
|
||
# Installer logs | ||
pip-log.txt | ||
|
||
# Unit test / coverage reports | ||
.coverage | ||
.tox | ||
|
||
#Translations | ||
*.mo | ||
|
||
#Mr Developer | ||
.mr.developer.cfg | ||
|
||
#myself | ||
data.db |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env python | ||
# coding=utf8 | ||
|
||
from sqlalchemy import Column, Integer, String, Unicode | ||
from sqlalchemy.orm import relationship, backref | ||
|
||
from meta import Base, session | ||
|
||
class Contact(Base): | ||
"""contact model""" | ||
__tablename__ = 'contact' | ||
|
||
id = Column(Integer, primary_key=True) | ||
name = Column(Unicode(50), nullable=False) | ||
|
||
#sms = relationship("Sms", order_by='Sms.id', backref='contact') | ||
|
||
def __init__(self, name): | ||
self.name = name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# coding=utf8 | ||
|
||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import scoped_session, sessionmaker | ||
from sqlalchemy import create_engine | ||
|
||
__all__ = ['Base', 'Session'] | ||
|
||
#engine = create_engine('sqlite:///:memory:', echo=True) | ||
engine = create_engine('sqlite:///data.db', echo=True) | ||
|
||
# SQLAlchemy session manager. Updated by model.init_model() | ||
Session = scoped_session(sessionmaker()) | ||
Session.configure(bind=engine) | ||
session = Session() | ||
|
||
# The declarative Base | ||
Base = declarative_base() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env python | ||
# coding=utf8 | ||
|
||
from sqlalchemy import Column, Integer, String, Unicode | ||
|
||
from meta import Base, Session | ||
|
||
class Phone(Base): | ||
"""contact model""" | ||
__tablename__ = 'phone' | ||
|
||
id = Column(Integer, primary_key=True) | ||
number = Column(String(50), nullable=False) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env python | ||
# coding=utf8 | ||
|
||
from sqlalchemy import Column, Integer, String | ||
from sqlalchemy import ForeignKey | ||
from sqlalchemy.orm import relationship, backref | ||
|
||
from meta import Base, session | ||
|
||
class Sms(Base): | ||
"""sms model""" | ||
__tablename__ = 'sms' | ||
|
||
id = Column(Integer, primary_key=True) | ||
from_contact_id = Column(Integer, ForeignKey('contact.id')) | ||
from_contact = relationship('Contact', backref='sms') | ||
|
||
content = Column(String(500)) | ||
# TODO create_at | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def add(self): | ||
session.add(self) | ||
session.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python | ||
# coding=utf8 | ||
|
||
from meta import session, Base | ||
from sms import Sms | ||
from contact import Contact | ||
|
||
class Smsir(object): | ||
"""A sms helper""" | ||
|
||
def __init__(self, session, Base): | ||
self.session = session | ||
self.Base = Base | ||
|
||
def create_all(self): | ||
Base.metadata.create_all() | ||
|
||
def import_from_xml(self): | ||
pass | ||
|
||
def import_from_txt(self): | ||
pass | ||
|
||
def test(self): | ||
sms = Sms() | ||
sms.from_contact = Contact(u'路飞') | ||
sms.add() |