$ pip install sqlobject
Downloading/unpacking sqlobject
Downloading SQLObject-1.5.1.tar.gz (276kB): 276kB downloaded
Running setup.py egg_info for package sqlobject
warning: no files found matching '*.html'
warning: no files found matching '*.css'
warning: no files found matching 'docs/*.html'
warning: no files found matching '*.py' under directory 'tests'
Requirement already satisfied (use --upgrade to upgrade): FormEncode>=1.1.1 in /Users/xiaonuogantan/python2-workspace/lib/python2.7/site-packages (from sqlobject)
Installing collected packages: sqlobject
Running setup.py install for sqlobject
changing mode of build/scripts-2.7/sqlobject-admin from 644 to 755
changing mode of build/scripts-2.7/sqlobject-convertOldURI from 644 to 755
warning: no files found matching '*.html'
warning: no files found matching '*.css'
warning: no files found matching 'docs/*.html'
warning: no files found matching '*.py' under directory 'tests'
changing mode of /Users/xiaonuogantan/python2-workspace/bin/sqlobject-admin to 755
changing mode of /Users/xiaonuogantan/python2-workspace/bin/sqlobject-convertOldURI to 755
Successfully installed sqlobject
Cleaning up...
>>> from sqlobject import StringCol, SQLObject, ForeignKey, sqlhub, connectionForURI
>>> sqlhub.processConnection = connectionForURI('sqlite:/:memory:')
>>>
>>> class Person(SQLObject):
... name = StringCol()
...
>>> class Address(SQLObject):
... address = StringCol()
... person = ForeignKey('Person')
...
>>> Person.createTable()
[]
>>> Address.createTable()
[]
>>> p = Person(name='person') >>> a = Address(address='address', person=p) >>> p >>> a <address>
>>> persons = Person.select(Person.q.name == 'person') >>> persons >>> list(persons) [] >>> p1 = persons[0] >>> p1 == p True >>> addresses = Address.select(Address.q.person == p1) >>> addresses >>> list(addresses) [ <address>] >>> a1 = addresses[0] >>> a1 == a True[b]Storm [/b]
>>> from storm.locals import Int, Reference, Unicode, create_database, Store
>>>
>>>
>>> db = create_database('sqlite:')
>>> store = Store(db)
>>>
>>>
>>> class Person(object):
... __storm_table__ = 'person'
... id = Int(primary=True)
... name = Unicode()
...
>>>
>>> class Address(object):
... __storm_table__ = 'address'
... id = Int(primary=True)
... address = Unicode()
... person_id = Int()
... person = Reference(person_id, Person.id)
...
>>> store.execute("CREATE TABLE person "
... "(id INTEGER PRIMARY KEY, name VARCHAR)")
>>> store.execute("CREATE TABLE address "
... "(id INTEGER PRIMARY KEY, address VARCHAR, person_id INTEGER, "
... " FOREIGN KEY(person_id) REFERENCES person(id))")
>>> person = Person()
>>> person.name = u'person'
>>> print person
>>> print "%r, %r" % (person.id, person.name)
None, u'person' # Notice that person.id is None since the Person instance is not attached to a valid database store yet.
>>> store.add(person)
>>> print "%r, %r" % (person.id, person.name)
None, u'person' # Since the store hasn't flushed the Person instance into the sqlite database yet, person.id is still None.
>>> store.flush()
>>> print "%r, %r" % (person.id, person.name)
1, u'person' # Now the store has flushed the Person instance, we got an id value for person.
>>> address = Address()
>>> address.person = person
>>> address.address = 'address'
>>> print "%r, %r, %r" % (address.id, address.person, address.address)
None, , 'address'
>>> address.person == person
True
>>> store.add(address)
>>> store.flush()
>>> print "%r, %r, %r" % (address.id, address.person, address.address)
1, , 'address'
>>> person = store.find(Person, Person.name == u'person').one() >>> print "%r, %r" % (person.id, person.name) 1, u'person' >>> store.find(Address, Address.person == person).one() >>> address = store.find(Address, Address.person == person).one() >>> print "%r, %r" % (address.id, address.address) 1, u'address'
$ django-admin.py startproject demo $ cd demo $ python manage.py syncdb Creating tables ... Creating table django_admin_log Creating table auth_permission Creating table auth_group_permissions Creating table auth_group Creating table auth_user_groups Creating table auth_user_user_permissions Creating table auth_user Creating table django_content_type Creating table django_session You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): no Installing custom SQL ... Installing indexes ... Installed 0 object(s) from 0 fixture(s) $ python manage.py shell
# demo/models.py >>> from django.db import models >>> >>> >>> class Person(models.Model): ... name = models.TextField() ... class Meta: ... app_label = 'demo' ... >>> >>> class Address(models.Model): ... address = models.TextField() ... person = models.ForeignKey(Person) ... class Meta: ... app_label = 'demo' ...
python manage.py syncdb Creating tables ... Creating table demo_person Creating table demo_address Installing custom SQL ... Installing indexes ... Installed 0 object(s) from 0 fixture(s)
>>> from demo.models import Person, Address >>> p = Person(name='person') >>> p.save() >>> print "%r, %r" % (p.id, p.name) 1, 'person' >>> a = Address(person=p, address='address') >>> a.save() >>> print "%r, %r" % (a.id, a.address) 1, 'address'
>>> persons = Person.objects.filter(name='person') >>> persons [] >>> p = persons[0] >>> print "%r, %r" % (p.id, p.name) 1, u'person' >>> addresses = Address.objects.filter(person=p) >>> addresses [ <address>] >>> a = addresses[0] >>> print "%r, %r" % (a.id, a.address) 1, u'address'
pip install peewee Downloading/unpacking peewee Downloading peewee-2.1.7.tar.gz (1.1MB): 1.1MB downloaded Running setup.py egg_info for package peewee Installing collected packages: peewee Running setup.py install for peewee changing mode of build/scripts-2.7/pwiz.py from 644 to 755 changing mode of /Users/xiaonuogantan/python2-workspace/bin/pwiz.py to 755 Successfully installed peewee Cleaning up...
>>> from peewee import SqliteDatabase, CharField, ForeignKeyField, Model
>>>
>>> db = SqliteDatabase(':memory:')
>>>
>>> class Person(Model):
... name = CharField()
... class Meta:
... database = db
...
>>>
>>> class Address(Model):
... address = CharField()
... person = ForeignKeyField(Person)
... class Meta:
... database = db
...
>>> Person.create_table()
>>> Address.create_table()
>>> p = Person(name='person') >>> p.save() >>> a = Address(address='address', person=p) >>> a.save()
>>> person = Person.select().where(Person.name == 'person').get() >>> person >>> print '%r, %r' % (person.id, person.name) 1, u'person' >>> address = Address.select().where(Address.person == person).get() >>> print '%r, %r' % (address.id, address.address) 1, u'address'
>>> from sqlalchemy import Column, String, Integer, ForeignKey >>> from sqlalchemy.orm import relationship >>> from sqlalchemy.ext.declarative import declarative_base >>> >>> >>> Base = declarative_base() >>> >>> >>> class Person(Base): ... __tablename__ = 'person' ... id = Column(Integer, primary_key=True) ... name = Column(String) ... >>> >>> class Address(Base): ... __tablename__ = 'address' ... id = Column(Integer, primary_key=True) ... address = Column(String) ... person_id = Column(Integer, ForeignKey(Person.id)) ... person = relationship(Person) ...
>>> from sqlalchemy import create_engine
>>> engine = create_engine('sqlite:///')
>>> from sqlalchemy.orm import sessionmaker >>> session = sessionmaker() >>> session.configure(bind=engine) >>> Base.metadata.create_all(engine)
>>> s = session() >>> p = Person(name='person') >>> s.add(p) >>> a = Address(address='address', person=p) >>> s.add(a)
>>> p = s.query(Person).filter(Person.name == 'person').one() >>> p >>> print "%r, %r" % (p.id, p.name) 1, 'person' >>> a = s.query(Address).filter(Address.person == p).one() >>> print "%r, %r" % (a.id, a.address) 1, 'address'
>>> s.commit() >>> s.close()
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有