- self.redirect(’/thanks’)
import cgi
cgi.escape(s, quote=True)
username = self.request.get('username')
USER_RE = re.compile(r'^[a-zA-Zd0-9_-{3,20}$')
USER_RE.match(username)
PASS_RE = re.compile(r'^.{3,20}$')
EMAIL_RE = re.compile(r'^[\S]+@[\S]+\.[\S]+$')
- html_template
- Django_template
Database: large, structured data
Tables | ||||||
---|---|---|---|---|---|---|
Link: | ID | votes | user | data | title | url |
User: | User | name | password |
-
downsides of query
error_prone, tedious, slow -
types of databases
- Rational SQL
- Postgre SQL - FREE
- MySQL - FREE
- SQLite (Light weight)
- Oracle (take from MySQL)
- Rational SQL
-
GAE’s Datastore
- Dynamo (Amazon) [Read Paper!]
- NoSQL
- mongo
- couch
-
SQL
- SELECT * FROM links WHERE id=5
-
Indexes (speed queries / slow inserts)
- dict in python
- hash - not sorted, lookup const time
- time - sorted, lookup log(n) time
- dict in python
-
Scaling Databases (too much load)
- master - slaves(replicate) - downsides
- doesn’t increase write speed
- replication lag
- shard (分割) - hash - downsides
- complex queries (range query)
- joins become difficult
- GAE Datastore
- joins
- complex queries
- tables -> entities
- columns are NOT fixed
- all have an ID
- parents/ancestors (Reddit->Link)
- master - slaves(replicate) - downsides
-
ACID
- Atomicity - transaction (multiple cmds)
- Consistency - synchronize updating
- Isolation - lock/not interference
- Durability - once committed, wait loss
-
SQL -> GQL
- ALL queries begin with SELECT *
- No joins
- run arbitrary queries -> all queries MUST be indexed
-
Datastore is sharded & replicated
- won’t think (too much) about scaling
- quick queries (because simple)
- will have to think about consistency
-
ASCII chan
- Datastore Types
- Integer
- Float
- String (<500 chars indexed)
- Date
- Time
- DateTime
- Link
- PostalAddress
- Text (>500 chars NOT indexed)
- Datastore Types
dev_appserver.py
appcfg.py
SLAC & big data, Mozilla, open source
- abstraction
- variable
- procedure
- list
- search index
- network
- dict
- hash
- universality
- if
- variable
- while procedure
- recursive definitions
What is CS?
- Engineering ( abstraction <-> constraint of human thought )
- Science ( computation in nature universality )
- Liberal Art ( 7 branches )
(class for db)
p = Post(title, content)
p.key().id() == 42
p = Post.get_by_id(42)
- DON’T user JOIN
- Make things independent
def foo(*a):
return a
>> foo()
>> ()
def render(*a, **kw):
return a, kw
>> render(1, 2, 3)
>> ((1, 2, 3), {})
- Framework (Quite similar)
- Django for python
- Ruby on Rails