Skip to content
0x6C77 edited this page Mar 16, 2013 · 7 revisions

A database is required because....

Kowalski, options

  • Non-proprietary
  • Simple, zero-configuration database
  • Relational makes things easy
  • Previous knowledge of SQL makes that a preferable language of choice
  • Simple python implementation.

A good place to start http://wiki.python.org/moin/DatabaseInterfaces

Flat-file, SQL based simple. No setup. Supports almost all SQL standard. Cons embedded into application no client-server mode

Advanced, client-server. Cons setup, not light. Supports things that are will not be needed

Dictionary type object that is persistent. Can store almost any object type easily.

Purely python, flat file. Can run embedded within an application or setup in client-server mode. Uses python expressions/regular expressions instead of SQL or other DB language. Non-relational.

MongoDB

NoSQL. Not used before but nice features

Possible solution - MongoDB

Currently most popular NoSQL DB. http://docs.mongodb.org/manual/core/geospatial-indexes/

Positives

Speed

High performance small read/writes are a good fit for MongoDB

Document orientated

flexible schemas allow - There is no predefined schema. A document structure is very simple: it follows the JSON format, and consists of a series of key-value pair.

2D Geospatial Indexes

http://docs.mongodb.org/manual/core/geospatial-indexes/

2d geospatial indexes make it possible to associate documents with locations in two-dimensional space, such as a point on a map. MongoDB interprets two-dimensional coordinates in a location field as points and can index these points in a special index type to support location-based queries. Geospatial indexes provide special geospatial query operators. For example, you can query for documents based on proximity to another location or based on inclusion in a specified region

Horizontal scaling

MongoDB scales horizontally using sharding

Database administrators have relied on scale up — buying bigger servers as database load increases — rather than scale out — distributing the database across multiple hosts as load increases NoSQL databases typically use clusters of cheap commodity servers to manage the exploding data and transaction volumes, while RDBMS tends to rely on expensive proprietary servers and storage systems

Others

  • Data stored in BSON, see flexible schemas
  • BSON is pretty much JSON, everyone loves JSON

Negatives

Setup

None really

Creating Collection

Created automatically on read (I think)

mongo MapWars

Creating document

As there is no schema to worry about you just shove stuff in

mongo MapWars
> db.createCollection('users')
{ "ok" : 1 }
> db.users.insert({user: 'flabbyrabbit', pass: 'dog'})
> db.users.find()
{ "_id" : ObjectId("513782058da9dcc2c66ea7aa"), "user" : "flabbyrabbit", "pass" : "dog" }

Python

http://docs.mongodb.org/ecosystem/drivers/python/

Instillation

git clone git://github.com/mongodb/mongo-python-driver.git pymongo
cd pymongo/
python setup.py install

Chosen solution - SQlite

SQL rocks

http://hoopercharles.wordpress.com/2011/06/13/calculate-the-distance-between-two-latitudelongitude-points-using-plain-sql/

http://zetcode.com/db/sqlitepythontutorial/