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

Error "cannot read property 'indexes' of undefined" on DROP TABLE #133

Closed
ajrcarey opened this issue Mar 23, 2019 · 2 comments
Closed

Error "cannot read property 'indexes' of undefined" on DROP TABLE #133

ajrcarey opened this issue Mar 23, 2019 · 2 comments
Labels

Comments

@ajrcarey
Copy link

@ajrcarey ajrcarey commented Mar 23, 2019

Using a pre-built minified version 2.2.1, creating a table and then dropping it results in an error:

Uncaught (in promise) TypeError: Cannot read property 'indexes' of undefined
    at Object.deleteIndex (nano-sql.min.js:1)
    at nano-sql.min.js:1
    at nano-sql.min.js:1
    at new Promise (<anonymous>)
    at nano-sql.min.js:1
    at Array.map (<anonymous>)
    at Object.t.allAsync (nano-sql.min.js:1)
    at nano-sql.min.js:1

The following script creates, then immediately deletes, a table, resulting in the error being printed to the console.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>NanoSQL DROP TABLE test</title>
    <meta charset="utf-8">
    <script src="https://cdn.jsdelivr.net/npm/@nano-sql/core@2.2.1/dist/nano-sql.min.js"></script>
</head>
<body>
</body>
<script>
    nSQL().connect({
        id: 'test',
        mode: 'TEMP',
        tables: [
            {
              name : 'users',
              model : {
                'id:uuid' : {'pk': true},
                'forename:string' : {},
                'surname:string' : {},
                'gender:string' : {},
                'age:int' : {},
                'education:string' : {},
                'occupation:string' : {},
                'salary:int' : {}
              },
              indexes: {
                'forename:string' : {},
                'surname:string' : {},
                'age:int' : {},
                'gender:string' : {},
                'education:string' : {},
                'occupation:string' : {},
                'salary:int' : {}
              }
            }
        ]
    }).then(() => {
        nSQL('users').query('drop').exec();
    });
</script>
</html>

The problem does not occur if the index definitions in the CREATE TABLE definition are commented out, i.e. the table has no indexes at the moment the DROP operation is executed. This suggests that it might be posisble to work around the problem by removing all indexes manually before attempting to DROP, but the wording of the documentation at https://nanosql.gitbook.io/docs/query/drop-table suggests that indexes should be removed automatically as part of the DROP operation.

@only-cliches
Copy link
Owner

@only-cliches only-cliches commented Mar 24, 2019

Thanks so much for reporting this! 2.2.2 has just been released and should resolve everything!

@ajrcarey
Copy link
Author

@ajrcarey ajrcarey commented Mar 25, 2019

Many thanks, I confirm the problem is resolved in 2.2.2.

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

Successfully merging a pull request may close this issue.

None yet
2 participants