capacitor-community / sqlite

⚡Capacitor plugin for native & electron SQLite databases.
MIT License
505 stars 121 forks source link

Compound primary Key when ImportFromJSON #71

Closed alu0100991659 closed 3 years ago

alu0100991659 commented 3 years ago

Hi, is it possible to define a compound primary key when creating a database from a JSON?

The example bellow didn't work

export const dataToImport = {
    database: "curieapp-db",
    version: 1,
    encrypted: false,
    mode: "full",
    tables: [
        {
            name: "modules",
            schema: [
                {
                    column: "id",
                    value: "INTEGER PRIMARY KEY NOT NULL"
                },
                {
                    column: "id2",
                    value: "INTEGER PRIMARY KEY NOT NULL"
                }
            ],
            indexes: [],
            values: [
                [ 6, 4 ],  [ 6, 5 ]
            ]
        }
    ]
}
jepiqueau commented 3 years ago

@alu0100991659 hi, thanks for using the plugin, it is a feature to implement, i will have to figure out

jepiqueau commented 3 years ago

@alu0100991659 This has been fixed in release 2.9.7. It is implemented with a CONSTRAINT example for using it

          name: 'company',
          schema: [
            { column: 'id', value: 'INTEGER NOT NULL' },
            { column: 'name', value: 'TEXT NOT NULL' },
            { column: 'age', value: 'INTEGER NOT NULL' },
            { column: 'address', value: 'TEXT' },
            { column: 'salary', value: 'REAL'},
            { column: "last_modified", value: "INTEGER"},
            { constraint: 'PK_id_name', value: 'PRIMARY KEY (id,name)'},
          ],
        },

if it works at your place, please close the issue

jepiqueau commented 3 years ago

@alu0100991659 has you did not send any news i close the issue

ghost commented 3 years ago

Sorry if i'm getting late to the issue but i tried this example and i'm getting the following error: "ImportFromJson: ImportJson: CreateDatabaseSchema: CreateSchema: Execute: SQLITE_ERROR: near ")": syntax error: ". If i remove the constraint it's working fine.

The problems is happening with electron platform

@alu0100991659 This has been fixed in release 2.9.7. It is implemented with a CONSTRAINT example for using it

          name: 'company',
          schema: [
            { column: 'id', value: 'INTEGER NOT NULL' },
            { column: 'name', value: 'TEXT NOT NULL' },
            { column: 'age', value: 'INTEGER NOT NULL' },
            { column: 'address', value: 'TEXT' },
            { column: 'salary', value: 'REAL'},
            { column: "last_modified", value: "INTEGER"},
            { constraint: 'PK_id_name', value: 'PRIMARY KEY (id,name)'},
          ],
        },

if it works at your place, please close the issue

jepiqueau commented 3 years ago

@jfernandino Are you on Windows ? i test on MacOs with Ionic/Angular and it works fine Did you run the "angular-sqlite-app-starter" ?

ghost commented 3 years ago

I'm using windows yes. I ran react-sqlite-app-starter and added one table with composite pk, using the example above. And the problemen is the same yes.

{"changes":{"changes":-1},"message":"ImportFromJson: ImportJson: CreateDatabaseSchema: CreateSchema: Execute: SQLITE_ERROR: near \")\": syntax error: "}

jepiqueau commented 3 years ago

@jfernandino On my side, it is working. see https://github.com/jepiqueau/react-sqlite-app-starter/tree/refactor . May be you forgot to run npx cap sync @capacitor-community/electron after installing the new version of @capacitor-community/sqlite. This is the only thing i can think about it.