Ionic-framework: Feature Request: Get transaction from SqlStorage

Created on 20 May 2016  路  13Comments  路  Source: ionic-team/ionic-framework

Short description of the problem:

Currently , it is not possible to get transaction directly from Storage with Ionic 2. The only way, is to make a request and get a transaction in return.

private storage = new Storage(SqlStorage, { name: 'myDatabase, location: 'default' });

this.storage.query("SELECT 'one request for transaction'")
            .then((response) => {
                response.tx.executeSql("CREATE TABLE IF NOT EXISTS USER (id integer primary key, name text");
                response.tx.executeSql("CREATE TABLE IF NOT EXISTS PROJECT (id integer primary key, name text");
            });

What behavior are you expecting?

Get transaction directly from SqlStorage

this.storage.transaction(function (transaction) {
    transaction.executeSql("CREATE TABLE IF NOT EXISTS USER (id integer primary key, name text");
    transaction.executeSql("CREATE TABLE IF NOT EXISTS PROJECT (id integer primary key, name text");
});

Ionic 2.x

Most helpful comment

Hi @jeromeXoo,

I will discuss with team and see what we can do about this. I like the idea, too, and have been playing around with it on some side projects.

I'll keep you posted. Please sit tight. Might be a few weeks. I have a few ideas of some cool things we can do to dramatically improve the SQL experience.

Thanks,
Dan

All 13 comments

Hi @jeromeXoo,

I will discuss with team and see what we can do about this. I like the idea, too, and have been playing around with it on some side projects.

I'll keep you posted. Please sit tight. Might be a few weeks. I have a few ideas of some cool things we can do to dramatically improve the SQL experience.

Thanks,
Dan

Seriously this should been done a long time ago, here's another issue request about exposing the transaction api: https://github.com/driftyco/ionic/issues/5245

is the ionic team going to address this issue? I'm really needing transactions especially for one-to-many relationships. Can anyone share some code that handles them?

Thanks!

@jfoscue,

We are currently refactoring storage.

Thanks,
Dan

Thanks @danbucholtz! Is there a timeline to expect the changes?

@jfoscue,

I would think before RC. No promises, though. So a few weeks most likely.

Thanks,
Dan

I hope so, i'm making a tutorial for the pluralsight's hack.guides() contest about database versioning ionic 2 apps but it looks just wrong to access the transaction from the private variable when i'm not supposed to.

Yeah, I hear you on that one @Luchillo. Thanks again for contributing.

Thanks,
Dan

I made the tests and with rollback.
this.storage.query("SELECT 1").then((response) => {
response.tx.executeSql("INSERT INTO TEST (descricao) VALUES(?)", [nome]);
response.tx.executeSql("INSERT INTO TEST (descricao) VALUES(?)", [nome]);
response.tx.executeSql("INSERT INTO TEST (descricao) VALUES(?)", [nome]);
response.tx.executeSql("INSERT INTO TEST (descricao) VALUES(?)", [nome]);
response.tx.executeSql("ROLLBACK");
});

Ok you did a test, now what, what're you trying to say?

Given the changes in ionic storage, this issue is now irrelevant.

Where I can see the new changes?

In the readme from Ionic-Storage: https://github.com/driftyco/ionic-storage

If you want to perform arbitrary SQL queries and have one of the best storage options around, we recommend using the Ionic Native SQLite plugin directly. This engine no longer supports the query feature underneath as it was not portable and only worked for SQLite anyways.

I m not from Ionic Team, but I think it is better to directly access SQLite, to take advantage of all the features without any intermediary. And Ionic-Storage goal is not to access a database but just to access a list of key/value.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

daveshirman picture daveshirman  路  3Comments

alexbainbridge picture alexbainbridge  路  3Comments

giammaleoni picture giammaleoni  路  3Comments

BilelKrichen picture BilelKrichen  路  3Comments

brandyscarney picture brandyscarney  路  3Comments