Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
84d2b3c4
Commit
84d2b3c4
authored
Jun 10, 2015
by
Chris Toshok
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add two very simple sqlalchemy tests. one works, one doesn't
parent
d2c03eaa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
137 additions
and
0 deletions
+137
-0
minibenchmarks/sqlalchemy-declarative.py
minibenchmarks/sqlalchemy-declarative.py
+72
-0
minibenchmarks/sqlalchemy-imperative.py
minibenchmarks/sqlalchemy-imperative.py
+65
-0
No files found.
minibenchmarks/sqlalchemy-declarative.py
0 → 100644
View file @
84d2b3c4
# this doesn't work in pyston at the moment
import
os
import
sys
sys
.
path
.
append
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"../test/integration/sqlalchemy/lib"
))
from
sqlalchemy
import
Column
,
ForeignKey
,
Integer
,
String
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy.orm
import
relationship
,
sessionmaker
from
sqlalchemy
import
create_engine
Base
=
declarative_base
()
class
Person
(
Base
):
__tablename__
=
'person'
# Here we define columns for the table person
# Notice that each column is also a normal Python instance attribute.
id
=
Column
(
Integer
,
primary_key
=
True
)
name
=
Column
(
String
(
250
),
nullable
=
False
)
class
Address
(
Base
):
__tablename__
=
'address'
# Here we define columns for the table address.
# Notice that each column is also a normal Python instance attribute.
id
=
Column
(
Integer
,
primary_key
=
True
)
street_name
=
Column
(
String
(
250
))
street_number
=
Column
(
String
(
250
))
post_code
=
Column
(
String
(
250
),
nullable
=
False
)
person_id
=
Column
(
Integer
,
ForeignKey
(
'person.id'
))
person
=
relationship
(
Person
)
# Create an engine that stores data in the local directory's
# sqlalchemy_example.db file.
engine
=
create_engine
(
'sqlite://'
)
# Create all tables in the engine. This is equivalent to "Create Table"
# statements in raw SQL.
Base
.
metadata
.
create_all
(
engine
)
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base
.
metadata
.
bind
=
engine
DBSession
=
sessionmaker
(
bind
=
engine
)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session
=
DBSession
()
# add 100 people to the database
for
i
in
xrange
(
100
):
# Insert a Person in the person table
new_person
=
Person
(
name
=
"new person %d"
%
(
i
,)
)
session
.
add
(
new_person
)
session
.
commit
()
# Insert an Address in the address table
new_address
=
Address
(
post_code
=
'00000'
,
person
=
new_person
)
session
.
add
(
new_address
)
session
.
commit
()
# now do 1000 queries
for
i
in
xrange
(
1000
):
session
.
query
(
Person
).
all
()
print
"done"
minibenchmarks/sqlalchemy-imperative.py
0 → 100644
View file @
84d2b3c4
import
os
import
sys
sys
.
path
.
append
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"../test/integration/sqlalchemy/lib"
))
from
sqlalchemy
import
Column
,
ForeignKey
,
Integer
,
String
,
Table
,
MetaData
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy.orm
import
relationship
,
sessionmaker
from
sqlalchemy
import
create_engine
metadata
=
MetaData
()
Person
=
Table
(
'person'
,
metadata
,
Column
(
'id'
,
Integer
,
primary_key
=
True
),
Column
(
'name'
,
String
(
250
),
nullable
=
False
)
)
Address
=
Table
(
'address'
,
metadata
,
Column
(
'id'
,
Integer
,
primary_key
=
True
),
Column
(
'street_name'
,
String
(
250
)),
Column
(
'street_number'
,
String
(
250
)),
Column
(
'post_code'
,
String
(
250
),
nullable
=
False
),
Column
(
'person_id'
,
Integer
,
ForeignKey
(
'person.id'
))
#person = relationship(Person) XXX
)
# Create an engine that stores data in the local directory's
# sqlalchemy_example.db file.
engine
=
create_engine
(
'sqlite://'
)
# Create all tables in the engine. This is equivalent to "Create Table"
# statements in raw SQL.
metadata
.
create_all
(
engine
)
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
metadata
.
bind
=
engine
DBSession
=
sessionmaker
(
bind
=
engine
)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session
=
DBSession
()
# add 100 people to the database
for
i
in
xrange
(
100
):
# Insert a Person in the person table
new_person
=
Person
.
insert
()
new_person
.
execute
(
name
=
"new person %d"
%
(
i
,)
)
# Insert an Address in the address table
new_address
=
Address
.
insert
()
new_address
.
execute
(
post_code
=
'00000'
)
#, person=new_person)
# now do 1000 queries
for
i
in
xrange
(
1000
):
s
=
Person
.
select
()
rs
=
s
.
execute
()
print
"done"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment