[storm] Writing sqlite database to disk

Jamu Kakar jkakar at kakar.ca
Sun Apr 4 17:19:54 BST 2010


Hi Kenny,

On Sun, Apr 4, 2010 at 4:13 PM, Kenny Meyer <knny.myer at gmail.com> wrote:
> I want to write my sqlite database on the disk. How do I do that with Storm?
>
> Can Storm do that, or expects it an already existing database on disk to which
> to connect?

It can do both: create a database on disk and also open an existing
database.

> I have been taking the tutorial and I'm conscious about that everything gets
> stored in memory only, but I need to store the data permanently.
> Also the Storm documentation doesn't give me a lot of information.
>
> My code:
>
> def create_databases():
>    database = create_database("sqlite:")

You need to change the above line to:

    database = create_database("sqlite:////path/to/database/file.db")

There are some details about the URI format in the manual:

https://storm.canonical.com/Manual#URIs

>    store = Store(database)
>
>    # Create table for Note
>    store.execute("CREATE TABLE note"
>                  "(id INTEGER PRIMARY KEY,\
>                    create_date DATETIME,\
>                    mod_date DATETIME,\
>                    content VARCHAR)",
>                  noresult=True)
>
>    # Create table for Tag
>    store.execute("CREATE TABLE tag"
>                  "(id INTEGER PRIMARY KEY,\
>                    name VARCHAR)",
>                  noresult=True)

I'm not sure if schema alteration functions require a commit, but in
general you need to commit if you want your changes to persist to
the database:

    store.commit()

> Answers and feedback are welcome.

I hope this helps.

Thanks,
J.



More information about the storm mailing list