I have found an answer here on how I can specify an AUTO_INCREMENT
on a secondary column in a multiple column index in MySQL e.g.
CREATE TABLE foo (
id INTEGER NOT NULL AUTO_INCREMENT,
grp INTEGER NOT NULL ,
name VARCHAR(64),
PRIMARY KEY (id, grp)
) ENGINE = MyISAM;
How would I extend a slick.driver.MySQL.api.Table
so that such a table is generated, if indeed it is at all possible? Difficulties I am having currently: (1) I don't know how to create a composite primary key in slick within the main create statement and (2) I don't know how to specify to use the MyISAM engine.
Update: Following @ulas
' advice, I used slick.codegen
to generate the slick data model from the (already created) SQL table. However, the data model cannot be used to then recreate the table - it generates two statements instead of one, and neither reference MyISAM. Regarding this, I have listed an issue in the slick github repos.
For now this leaves me with following @RickJames
' advice, which I would rather do anyway since it doesn't rely on MyISAM, a non-default engine for the current version of MySQL.
So my question can now be collapsed to, how would I execute the following using slick?
BEGIN;
SELECT @id := IFNULL(MAX(id), -1) + 1 FROM foo WHERE grp = 1 FOR UPDATE;
INSERT INTO foo VALUES (@id, 1, 'bar');
COMMIT;
I have no idea how to do it using the 'higher-level' abstraction, so I tried following the Plain SQL Queries section of the slick manual. My attempt went something like:
val statements = DBIO.seq(
sqlu" SELECT @id := IFNULL(MAX(id), -1) + 1 FROM foo WHERE grp = 1 FOR UPDATE",
sqlu"INSERT INTO foo VALUES (@id, 1, 'bar')"
)
db.run(statements.transactionally)
But I got the error:
Exception in thread "main" slick.SlickException: Update statements should not return a ResultSet
Help appreciated.