I need to write a result set from MySQL ina csv format inside a bucket in Google Cloud Storage.
Following the instructions here, I created the following example code:
import cloudstorage
from google.appengine.api import app_identity
import db # My own Mysql wrapper
dump = db.get_table_dump(schema) # Here I made a simples SQL SELECT and fetchall()
bucket_name = app_identity.get_default_gcs_bucket_name()
file_name = "/" + bucket_name + "/finalfiles/" + schema + "/" +"myfile.csv"
with cloudstorage.open(file_name, "w") as gcsFile:
gcsFile.write(dump)
It did not work 'cause write
expects a string parameter and dump
is tuple of tuples result from fetchall()
.
I can't use this approach (or similar) since I can't write files in GAE enviroment and I also can't create a CSV string from tuple like here, due to the size o my result set (Actually, I tried it and it takes too long and it timed out before finish).
So, my question is, which is the best way to get a result set from MySQL and save it as CSV in a Google Cloud Storage Bucket?