Skip to content
This repository has been archived by the owner on Jul 13, 2020. It is now read-only.

Ability to create table with composite Primary Key #547

Open
maximelovino opened this issue Jan 14, 2018 · 1 comment
Open

Ability to create table with composite Primary Key #547

maximelovino opened this issue Jan 14, 2018 · 1 comment

Comments

@maximelovino
Copy link

I was wondering if there was a way to use a composite Primary Key when using db.createTable to create a table. When reading through the wiki and issues, I couldn't find one. I was hoping to find something in the style of the FOREIGN_KEY() implementation as seen in #258 .

The expected behaviour would be

db.createTable(
    ActivityEntry.TABLE_NAME,
    true,
    ActivityEntry.COLUMN_USER_ID to INTEGER + NOT_NULL,
    ActivityEntry.COLUMN_ACTIVITY_NAME to TEXT + NOT_NULL,
    PRIMARY_KEY(ActivityEntry.COLUMN_USER_ID,ActivityEntry.COLUMN_ACTIVITY_NAME),
    FOREIGN_KEY(ActivityEntry.COLUMN_USER_ID,UserEntry.TABLE_NAME,UserEntry.COLUMN_ID))
@blackstardlb
Copy link

blackstardlb commented Aug 20, 2018

fun PRIMARY_KEY(vararg columnNames: String): Pair<String, SqlType> {
    return "" to SqlType.create("PRIMARY KEY (${actions.joinToString(", ")}})")
}

db.createTable(crossTableName, true,
        "class_id" to TEXT,
        "schedule_id" to TEXT,
        FOREIGN_KEY("class_id", hhsClassTableName, "id", ON_DELETE(ConstraintActions.NO_ACTION)),
        FOREIGN_KEY("schedule_id", followableTableName, "id", ON_DELETE(ConstraintActions.CASCADE)),
        PRIMARY_KEY("class_id", "schedule_id")
)

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

No branches or pull requests

2 participants