7

Is there anyway to open and read a SQLite database file on GAE?

I am currently uploading dbs to blobstore as admin and serving them publicly to user clients. I just can't read them in the GAE admin interface.

Jonny
  • 15,955
  • 18
  • 111
  • 232
  • Looks like its not possible with standard python libraries, but maybe you can find pure python sqlite library. – Dmytro Sadovnychyi Jan 28 '15 at 04:43
  • sqlite is not currently among the Python extensions supported by GAE -- you'd need to use Cloud SQL in lieu of sqlite, or a Managed VM in lieu of "GAE proper". Or write your own dashboard to view/manage those sqlite DBs living in blobstore (or rather I hope in Google Cloud Storage!) as the GAE admin interface will most assuredly *never* support sqlite anyway. – Alex Martelli Jan 28 '15 at 05:16
  • I was talking about the admin interface I wrote on my app... I don't need to modify the sqlite db, just open and read using Python. I won't need to fiddle with the contents from GAE admin console interface, I'm fine with the db just being a blob. In memory though we should be able to do whatever... somehow. Like Dmitry says, a pure Python sqlite library should do it. For that matter we should then also be able to edit the db in memory, then save the content to datastore :-P Sqlite is just another format like JSON. – Jonny Jan 28 '15 at 07:28
  • I don't think blobstore supports the kind of random file access you would need to query a database. Maybe you could read it into an in-memory db, as suggested [in this answer](http://stackoverflow.com/questions/3850022/python-sqlite3-load-existing-db-file-to-memory). – Daniel Roseman Jan 28 '15 at 09:53
  • I think we are not talking about the same thing. I have loaded the db into memory already; I need a python library to parse it. I found http://www.pydblite.net but couldn't get it to work yet. – Jonny Jan 30 '15 at 08:56

2 Answers2

5

You can use SQLITE on Google App Engine. The problem has nothing to do with the support of certain libraries. It has to do with read-only file system. There is, however, a writable /tmp directory. If your app on startup first copies the db.sqlite3 file to /tmp/db.sqlite3 and references this path as database path, it will work.

There are, however, drawbacks. 1. This is not a "real" directory i.e. it's stored im memory. If database is too large, one will get problems. 2. Each instance has its own copy of db.sqlite3 file. Does not scale well.

Here is a django example: Using SQLITE for local Django development for Google App Engine?

Fedor Petrov
  • 990
  • 9
  • 19
3

Short answer, no it is not possible to use a SQLite database on a standard Google App Engine application as it is not currently supported. However, you can give a try at implementing your own configuration with the App Engine Flexible Environment that allows to take advantage of custom libraries through Infrastructure Customization.

In case you would want to experiment, here is a sample Django application designed to be run with its default SQLite database on the App Engine Flexible Environment. Still, make sure to read the database notice providing alternative data storage options and explaining that SQLite data does not persist upon instance restart.

Alex
  • 315
  • 5
  • 17