Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WebSQL] How to avoid duplicate index definition? #98

Open
iseki-masaya opened this issue Mar 3, 2016 · 3 comments
Open

[WebSQL] How to avoid duplicate index definition? #98

iseki-masaya opened this issue Mar 3, 2016 · 3 comments
Labels

Comments

@iseki-masaya
Copy link

Hi,

I run the below code at Google Chrome(v48) and Safari(v9) on MacOSX(v10.11).

var db = new ydn.db.Storage('MyDB', {
 stores: [
  {
    name: 'test',
    keyPath: 'id',
    indexes: [
       {
      keyPath: ['first', 'last']
       },
       {
         keyPath: 'first'
       },
       {
         keyPath: 'last'
       }
     ]
}, {mechanisms: ['websql']});

db.put('test', {id: 1, first: 'First', last: 'Last'});
db.put('test', {id: 2, first: 'First', last: 'Last'});

db.from('test').where('first', '=', 'First').order('last').list(20)
.done( (data) => {
  console.log(data);
})
.fail( (err) => {
  console.log(err);
})

This script works correctly for the first time. However, I got the below error(Chrome) from the second time.

ydn.error.ArgumentException: index "first, last" already defined in store: test

There are no error using IndexedDB however we need to support iOS and Android.
Is there way to avoid duplicate index definition?

Thanks

yathit added a commit that referenced this issue Mar 3, 2016
@yathit yathit added the bug label Mar 3, 2016
yathit added a commit that referenced this issue Mar 6, 2016
@mehdirande
Copy link
Contributor

Hi,
I'm also bothered by this issue,
@iseki-masaya : a simple way to avoid this problem is to switch the order of youre indexes definition. By declaring the composite index in last, the bug is not trigered.
@yathit : I might submit a PR about this bug, the fix seems to bo simple but i'm not sure about this. In ydn.db.schema.Store you use name.indexOf(otherName) >= 0 to match index name. By doing this first and last match first, last and that's what is triggering the bug.
Since I don't understand why you use indexOf instead of = I'm not sure about what is going to break if I fix it this way..

yathit added a commit that referenced this issue Oct 27, 2016
yathit added a commit that referenced this issue Oct 27, 2016
@yathit
Copy link
Owner

yathit commented Oct 27, 2016

@mehdirande As far I remember, WebSQL has problem with reflection on composite index.

Where is name.indexOf(otherName) >= 0? If you submit PR, I will see.

@mehdirande
Copy link
Contributor

Okay done, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants