Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Added database-specific code.

* Updated the tools module in the example with actual implementation for
  importing csv data into Riak.
  • Loading branch information...
commit 0ac94a39d8c5e9396bb1ab5202fbd1e5e1f8edeb 1 parent 4a65206
Duncan M. McGreggor authored
View
43 django_riak_engine/db.py
@@ -0,0 +1,43 @@
+from django_riak_engine import client
+
+from djangotoolbox.db.base import NonrelDatabaseFeatures, \
+ NonrelDatabaseOperations, NonrelDatabaseWrapper, \
+ NonrelDatabaseValidation, NonrelDatabaseIntrospection, \
+ NonrelDatabaseCreation
+
+
+# TODO: You can either use the type mapping defined in NonrelDatabaseCreation
+# or you can override the mapping, here:
+class DatabaseCreation(NonrelDatabaseCreation):
+ pass
+
+
+class DatabaseFeatures(NonrelDatabaseFeatures):
+ pass
+
+
+class DatabaseOperations(NonrelDatabaseOperations):
+ compiler_module = __name__.rsplit('.', 1)[0] + '.compiler'
+
+
+class DatabaseValidation(NonrelDatabaseValidation):
+ pass
+
+
+class DatabaseIntrospection(NonrelDatabaseIntrospection):
+ pass
+
+
+class DatabaseWrapper(NonrelDatabaseWrapper):
+ def __init__(self, *args, **kwds):
+ super(DatabaseWrapper, self).__init__(*args, **kwds)
+ self.features = DatabaseFeatures(self)
+ self.ops = DatabaseOperations(self)
+ self.client = client.DatabaseClient(self)
+ self.creation = DatabaseCreation(self)
+ self.validation = DatabaseValidation(self)
+ self.introspection = DatabaseIntrospection(self)
+ # TODO: connect to your DB here (if needed)
+ self.db_connection = connect(
+ self.settings_dict['HOST'], self.settings_dict['PORT'],
+ self.settings_dict['USER'], self.settings_dict['PASSWORD'])
View
19 examples/django_riak_mapreduce/riak_mapreduce/tools.py
@@ -5,10 +5,21 @@
def import_csv_google_data():
# set up client
-
+ client = riak.RiakClient(
+ host="127.0.0.1", port=8087, transport_class=riak.RiakPbcTransport)
# set up bucket
-
+ bucket = client.bucket('google-stock-data')
# read in CSV data
-
+ reader = csv.DictReader(open("data/goog.csv", "rb"))
# iterate through the rows and put them in the bucket
- pass
+ count = 0
+ for row in reader:
+ print ".",
+ stock_quote = bucket.new(row.get("Date"), data=row)
+ try:
+ stock_quote.store()
+ except Exception, error:
+ print "Error while attempting to insert row %s" % count
+ raise error
+ count += 1
+ print "\nDONE. Imported %s rows into Riak." % count
Please sign in to comment.
Something went wrong with that request. Please try again.