Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MySQL:
- CREATE DATABASE `students`;
- // build.sbt:
- libraryDependencies ++= Seq(evolutions, jdbc)
- // application.conf:
- db.students {
- driver="com.mysql.jdbc.Driver"
- url="jdbc:mysql://localhost/students?useSSL=false"
- username="root"
- password="1234"
- }
- play.evolutions {
- # enable evolutions
- enabled = true # default is true
- # schema in which the generated evolution and lock tables will be saved to
- schema = students # default is no schema
- # unset autoCommit, so that evolutions will be applied in a single transaction
- autocommit = false # default is true
- # set useLocks, if you have many Play nodes that may potentially run evolutions
- useLocks = true # default is false
- # in dev mode, autoApply will cause both ups and downs evolutions to be automatically applied (only ups in prod)
- autoApply = true # default is false
- # in prod mode, this will cause down evolutions to be automatically applied (no effect in dev)
- autoApplyDowns = false # default is false
- }
- // create folder conf/evolutions/students and create file "1.sql":
- # students schema, faculty table
- # --- !Ups
- CREATE TABLE `faculty` (
- `faculty_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'primary key',
- `name` VARCHAR(64) NOT NULL COMMENT 'faculty name',
- `isArts` BOOLEAN NOT NULL COMMENT 'whether a faculty is Arts School',
- PRIMARY KEY (`faculty_id`),
- UNIQUE INDEX `faculty_name` (`name`)
- ) COMMENT='faculty table' COLLATE='utf8_general_ci' ENGINE=InnoDB;
- # --- !Downs
- DROP TABLE IF EXISTS `faculty`;
- '// ready! Start the server and run http://localhost:9000 and see what will happen to `students` DB
- // (2018-02-28) Bonus: let's add Slick to our Play project!
- // build.sbt
- libraryDependencies += "com.typesafe.play" %% "play-slick" % "3.0.1"
- libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.41" // put the driver from your DBMS
- // application.conf
- slick.dbs.students {
- profile = "slick.jdbc.MySQLProfile$"
- db {
- driver = "com.mysql.jdbc.Driver"
- url = "jdbc:mysql://localhost/students?useSSL=false"
- user = "root"
- password = "1234"
- }
- }
- // how to create DAO see at https://pastebin.com/Pa1Ub1Ri
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement