Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
corepost
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
nexlab
corepost
Commits
1259ce7c
Commit
1259ce7c
authored
Mar 22, 2012
by
Jacek Furmankiewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
aborting sqlalchemy experiment, focus on raw SQL instead
parent
2cb1544c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
5 additions
and
128 deletions
+5
-128
__init__.py
corepost/__init__.py
+5
-0
sqlalchemy.py
corepost/ext/sql/sqlalchemy.py
+0
-5
sqlalchemy_resource.py
corepost/test/sqlalchemy_resource.py
+0
-123
No files found.
corepost/__init__.py
View file @
1259ce7c
...
@@ -52,3 +52,8 @@ class AlreadyExistsException(ConflictException):
...
@@ -52,3 +52,8 @@ class AlreadyExistsException(ConflictException):
"""Standard 409 exception when REST resource already exists during a POST"""
"""Standard 409 exception when REST resource already exists during a POST"""
def
__init__
(
self
,
resourceName
,
invalidValue
,
message
):
def
__init__
(
self
,
resourceName
,
invalidValue
,
message
):
ConflictException
.
__init__
(
self
,
resourceName
,
invalidValue
,
"
%
s already exists"
%
resourceName
)
ConflictException
.
__init__
(
self
,
resourceName
,
invalidValue
,
"
%
s already exists"
%
resourceName
)
class
InternalServerException
(
RESTException
):
"""Standard 500 error"""
def
__init__
(
self
,
safeErrorMessage
):
RESTException
.
__init__
(
self
,
Response
(
500
,
safeErrorMessage
))
corepost/ext/sql/sqlalchemy.py
deleted
100644 → 0
View file @
2cb1544c
'''
Integration for SQLAlchemy.
@author: jacekf
'''
corepost/test/sqlalchemy_resource.py
deleted
100644 → 0
View file @
2cb1544c
'''
SQL Alchemy example application
@author: jacekf
'''
from
corepost
import
Response
,
NotFoundException
,
AlreadyExistsException
from
corepost.web
import
RESTResource
,
route
,
Http
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy
import
Column
,
Integer
,
String
,
ForeignKey
from
sqlalchemy.orm
import
relationship
,
backref
,
Session
# support different sessions for read/writes for master/read slave configuration
class
WriteSession
(
Session
):
"""SQL Alchemy session for writes (to master)"""
def
__init__
(
self
):
Session
.
__init__
(
self
)
class
ReadSession
(
Session
):
"""SQL Alchemy session for reads (from read slaves)"""
def
__init__
(
self
):
Session
.
__init__
(
self
)
# SQL Alchemy entities
Base
=
declarative_base
()
class
Customer
(
Base
):
"""Represents customer entity"""
__tablename__
=
"customer"
customerId
=
Column
(
"customer_id"
,
Integer
,
primary_key
=
True
)
firstName
=
Column
(
"first_name"
,
String
(
50
))
middleName
=
Column
(
"middle_name"
,
String
(
50
),
nullable
=
True
)
lastName
=
Column
(
"last_name"
,
String
(
50
))
def
__init__
(
self
,
customerId
,
firstName
,
middleName
,
lastName
):
(
self
.
customerId
,
self
.
firstName
,
self
.
middleName
,
self
.
lastName
)
=
(
customerId
,
firstName
,
middleName
,
lastName
)
class
CustomerAddress
(
Base
):
"""Represents customer address entity"""
addressId
=
Column
(
"address_id"
,
Integer
,
primary_key
=
True
)
addressLine1
=
Column
(
"address_line1"
,
String
(
255
))
addressLine2
=
Column
(
"address_line2"
,
String
(
255
),
nullable
=
True
)
city
=
Column
(
"city"
,
String
(
50
))
stateCode
=
Column
(
"state_code"
,
String
(
2
))
countryCode
=
Column
(
"country_code"
,
String
(
2
))
def
__init__
(
self
,
addressLine1
,
addressLine2
,
city
,
stateCode
,
countryCode
):
(
self
.
addressLine1
,
self
.
addressLine2
,
self
.
city
,
self
.
stateCode
,
self
.
countryCode
)
=
(
addressLine1
,
addressLine2
,
city
,
stateCode
,
countryCode
)
class
CustomerDAO
:
"""SQLAlchemy DAO that uses blocking I/O. Needs to always be run in defer.deferToThread()"""
def
findById
(
self
,
customerId
):
pass
def
save
(
self
,
customer
):
pass
def
merge
(
self
,
customer
):
pass
def
delete
(
self
,
customer
):
pass
# REST services
class
CustomerREST
:
"""Customer REST service"""
path
=
"/customer"
@
route
(
"/"
,
Http
.
GET
)
def
getAll
(
self
,
request
,
**
kwargs
):
pass
@
route
(
"/<customerId>"
,
Http
.
GET
)
def
get
(
self
,
request
,
customerId
,
**
kwargs
):
pass
@
route
(
"/"
,
Http
.
POST
)
def
post
(
self
,
request
,
customerId
,
firstName
,
middleName
=
None
,
lastName
,
**
kwargs
):
pass
@
route
(
"/<customerId>"
,
Http
.
PUT
)
def
put
(
self
,
request
,
customerId
,
firstName
=
None
,
middleName
=
None
,
lastName
=
None
,
**
kwargs
):
pass
@
route
(
"/<customerId>"
,
Http
.
DELETE
)
def
delete
(
self
,
request
,
customerId
,
**
kwargs
):
pass
class
CustomerAddressREST
:
"""Customer Address REST service"""
path
=
"/customer/<customerId>/address"
@
route
(
"/"
,
Http
.
GET
)
def
getAll
(
self
,
request
,
**
kwargs
):
pass
@
route
(
"/<addressId>"
,
Http
.
GET
)
def
get
(
self
,
request
,
customerId
,
addressId
,
**
kwargs
):
pass
@
route
(
"/"
,
Http
.
POST
)
def
post
(
self
,
request
,
customerId
,
addressId
,
addressLine1
,
addressLine2
=
None
,
city
,
stateCode
,
countryCode
,
**
kwargs
):
pass
@
route
(
"/<addressId>"
,
Http
.
PUT
)
def
put
(
self
,
request
,
customerId
,
self
,
request
,
customerId
,
addressId
,
addressLine1
=
None
,
addressLine2
=
None
,
city
=
None
,
stateCode
=
None
,
countryCode
=
None
,
**
kwargs
):
pass
@
route
(
"/<addressId>"
,
Http
.
DELETE
)
def
delete
(
self
,
request
,
customerId
,
addressId
,
**
kwargs
):
pass
def
run_sqlalchemy_app
():
app
=
RESTResource
((
CustomerREST
(),
CustomerAddressREST
()))
app
.
run
(
8086
)
pass
if
__name__
==
"__main__"
:
run_sqlalchemy_app
()
\ No newline at end of file
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