Skip to content

Commit b780cbe

Browse files
committed
Merge branch 'release/0.3.4'
2 parents e77cbc6 + 9e341cb commit b780cbe

File tree

10 files changed

+160
-135
lines changed

10 files changed

+160
-135
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ Add `scalikejdbc-async` to your dependencies.
3131
```scala
3232
libraryDependencies ++= Seq(
3333
"org.scalikejdbc" %% "scalikejdbc-async" % "[0.3,)",
34-
"com.github.mauricio" %% "postgresql-async" % "0.2.8",
35-
"com.github.mauricio" %% "mysql-async" % "0.2.8",
34+
"com.github.mauricio" %% "postgresql-async" % "0.2.10",
35+
"com.github.mauricio" %% "mysql-async" % "0.2.10",
3636
"org.slf4j" % "slf4j-simple" % "[1.7,)" // slf4j implementation
3737
)
3838
```
@@ -43,7 +43,7 @@ If you're a Play2 user, use play-plugin too!
4343
val appDependencies = Seq(
4444
"org.scalikejdbc" %% "scalikejdbc-async" % "[0.3,)",
4545
"org.scalikejdbc" %% "scalikejdbc-async-play-plugin" % "[0.3,)",
46-
"com.github.mauricio" %% "postgresql-async" % "0.2.8"
46+
"com.github.mauricio" %% "postgresql-async" % "0.2.10"
4747
)
4848
```
4949

core/src/main/scala/scalikejdbc/async/AsyncDBSession.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,11 @@ case class TxAsyncDBSession(connection: NonSharedAsyncConnection) extends AsyncD
328328

329329
def isActive: Boolean = connection.isActive
330330

331-
def begin(): Future[AsyncQueryResult] = connection.sendQuery("BEGIN")
331+
def begin()(implicit ctx: EC = ECGlobal): Future[AsyncQueryResult] = connection.sendQuery("BEGIN")
332332

333-
def rollback(): Future[AsyncQueryResult] = connection.sendQuery("ROLLBACK")
333+
def rollback()(implicit ctx: EC = ECGlobal): Future[AsyncQueryResult] = connection.sendQuery("ROLLBACK")
334334

335-
def commit(): Future[AsyncQueryResult] = connection.sendQuery("COMMIT")
335+
def commit()(implicit ctx: EC = ECGlobal): Future[AsyncQueryResult] = connection.sendQuery("COMMIT")
336336

337337
def release(): Unit = connection.release()
338338

play-sample/app/controllers/Companies.scala

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import play.api.data._, Forms._, validation.Constraints._
66
import org.json4s._, ext.JodaTimeSerializers
77
import com.github.tototoshi.play2.json4s.native._
88

9+
import scala.concurrent.Future
910
import scala.concurrent.ExecutionContext.Implicits.global
1011

1112
import models._
@@ -14,17 +15,13 @@ object Companies extends Controller with Json4s {
1415

1516
implicit val formats = DefaultFormats ++ JodaTimeSerializers.all
1617

17-
def all = Action {
18-
Async {
19-
Company.findAll.map(companies => Ok(Extraction.decompose(companies)))
20-
}
18+
def all = Action.async {
19+
Company.findAll.map(companies => Ok(Extraction.decompose(companies)))
2120
}
2221

23-
def show(id: Long) = Action {
24-
Async {
25-
Company.find(id) map { companyOpt =>
26-
companyOpt map { company => Ok(Extraction.decompose(company)) } getOrElse NotFound
27-
}
22+
def show(id: Long) = Action.async {
23+
Company.find(id) map { companyOpt =>
24+
companyOpt map { company => Ok(Extraction.decompose(company)) } getOrElse NotFound
2825
}
2926
}
3027

@@ -37,27 +34,21 @@ object Companies extends Controller with Json4s {
3734
)(CompanyForm.apply)(CompanyForm.unapply)
3835
)
3936

40-
def create = Action { implicit req =>
37+
def create = Action.async { implicit req =>
4138
companyForm.bindFromRequest.fold(
42-
formWithErrors => BadRequest("invalid parameters"),
43-
form => {
44-
Async {
45-
Company.create(name = form.name, url = form.url).map { company =>
46-
Created.withHeaders(LOCATION -> s"/companies/${company.id}")
47-
}
48-
}
39+
formWithErrors => Future.successful(BadRequest("invalid parameters")),
40+
form => Company.create(name = form.name, url = form.url).map { company =>
41+
Created.withHeaders(LOCATION -> s"/companies/${company.id}")
4942
}
5043
)
5144
}
5245

53-
def delete(id: Long) = Action {
54-
Async {
55-
Company.find(id).map { companyOpt =>
56-
companyOpt map { company =>
57-
company.destroy()
58-
NoContent
59-
} getOrElse NotFound
60-
}
46+
def delete(id: Long) = Action.async {
47+
Company.find(id).map { companyOpt =>
48+
companyOpt map { company =>
49+
company.destroy()
50+
NoContent
51+
} getOrElse NotFound
6152
}
6253
}
6354

play-sample/app/controllers/Programmers.scala

Lines changed: 49 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import play.api.data._, Forms._, validation.Constraints._
55

66
import org.json4s._, ext.JodaTimeSerializers
77
import com.github.tototoshi.play2.json4s.native._
8+
9+
import scala.concurrent.Future
810
import scala.concurrent.ExecutionContext.Implicits.global
911

1012
import models._
@@ -13,17 +15,13 @@ object Programmers extends Controller with Json4s {
1315

1416
implicit val formats = DefaultFormats ++ JodaTimeSerializers.all
1517

16-
def all = Action {
17-
Async {
18-
Programmer.findAll.map(programmers => Ok(Extraction.decompose(programmers)))
19-
}
18+
def all = Action.async {
19+
Programmer.findAll.map(programmers => Ok(Extraction.decompose(programmers)))
2020
}
2121

22-
def show(id: Long) = Action {
23-
Async {
24-
Programmer.find(id).map { programmerOpt =>
25-
programmerOpt map { programmer => Ok(Extraction.decompose(programmer)) } getOrElse NotFound
26-
}
22+
def show(id: Long) = Action.async {
23+
Programmer.find(id).map { programmerOpt =>
24+
programmerOpt map { programmer => Ok(Extraction.decompose(programmer)) } getOrElse NotFound
2725
}
2826
}
2927

@@ -36,82 +34,68 @@ object Programmers extends Controller with Json4s {
3634
)(ProgrammerForm.apply)(ProgrammerForm.unapply)
3735
)
3836

39-
def create = Action { implicit req =>
37+
def create = Action.async { implicit req =>
4038
programmerForm.bindFromRequest.fold(
41-
formWithErrors => BadRequest("invalid parameters"),
42-
form => {
43-
Async {
44-
Programmer.create(name = form.name, companyId = form.companyId).map { programmer =>
45-
Created.withHeaders(LOCATION -> s"/programmers/${programmer.id}")
46-
}
47-
}
39+
formWithErrors => Future.successful(BadRequest("invalid parameters")),
40+
form => Programmer.create(name = form.name, companyId = form.companyId).map { programmer =>
41+
Created.withHeaders(LOCATION -> s"/programmers/${programmer.id}")
4842
}
4943
)
5044
}
5145

52-
def addSkill(programmerId: Long, skillId: Long) = Action {
53-
Async {
54-
Programmer.find(programmerId).map { programmerOpt =>
55-
programmerOpt map { programmer =>
56-
try {
57-
Skill.find(skillId).map { skillOpt =>
58-
skillOpt map { skill => programmer.addSkill(skill) }
59-
}
60-
Ok
61-
} catch { case e: Exception => Conflict }
62-
} getOrElse NotFound
63-
}
64-
}
65-
}
66-
67-
def deleteSkill(programmerId: Long, skillId: Long) = Action {
68-
Async {
69-
Programmer.find(programmerId).map { programmerOpt =>
70-
programmerOpt map { programmer =>
46+
def addSkill(programmerId: Long, skillId: Long) = Action.async {
47+
Programmer.find(programmerId).map { programmerOpt =>
48+
programmerOpt map { programmer =>
49+
try {
7150
Skill.find(skillId).map { skillOpt =>
7251
skillOpt map { skill => programmer.addSkill(skill) }
7352
}
7453
Ok
75-
} getOrElse NotFound
76-
}
54+
} catch { case e: Exception => Conflict }
55+
} getOrElse NotFound
7756
}
7857
}
7958

80-
def joinCompany(programmerId: Long, companyId: Long) = Action {
81-
Async {
82-
for {
83-
companyOpt <- Company.find(companyId)
84-
programmerOpt <- Programmer.find(programmerId)
85-
} yield {
86-
companyOpt map { company =>
87-
programmerOpt.map { programmer =>
88-
programmer.copy(companyId = Some(company.id)).save()
89-
Ok
90-
} getOrElse BadRequest("Programmer not found!")
91-
} getOrElse BadRequest("Company not found!")
92-
}
59+
def deleteSkill(programmerId: Long, skillId: Long) = Action.async {
60+
Programmer.find(programmerId).map { programmerOpt =>
61+
programmerOpt map { programmer =>
62+
Skill.find(skillId).map { skillOpt =>
63+
skillOpt map { skill => programmer.addSkill(skill) }
64+
}
65+
Ok
66+
} getOrElse NotFound
9367
}
9468
}
9569

96-
def leaveCompany(programmerId: Long) = Action {
97-
Async {
98-
Programmer.find(programmerId).map { programmerOpt =>
99-
programmerOpt map { programmer =>
100-
programmer.copy(companyId = None).save()
70+
def joinCompany(programmerId: Long, companyId: Long) = Action.async {
71+
for {
72+
companyOpt <- Company.find(companyId)
73+
programmerOpt <- Programmer.find(programmerId)
74+
} yield {
75+
companyOpt map { company =>
76+
programmerOpt.map { programmer =>
77+
programmer.copy(companyId = Some(company.id)).save()
10178
Ok
10279
} getOrElse BadRequest("Programmer not found!")
103-
}
80+
} getOrElse BadRequest("Company not found!")
10481
}
10582
}
10683

107-
def delete(id: Long) = Action {
108-
Async {
109-
Programmer.find(id).map { programmerOpt =>
110-
programmerOpt map { programmer =>
111-
programmer.destroy()
112-
NoContent
113-
} getOrElse NotFound
114-
}
84+
def leaveCompany(programmerId: Long) = Action.async {
85+
Programmer.find(programmerId).map { programmerOpt =>
86+
programmerOpt map { programmer =>
87+
programmer.copy(companyId = None).save()
88+
Ok
89+
} getOrElse BadRequest("Programmer not found!")
90+
}
91+
}
92+
93+
def delete(id: Long) = Action.async {
94+
Programmer.find(id).map { programmerOpt =>
95+
programmerOpt map { programmer =>
96+
programmer.destroy()
97+
NoContent
98+
} getOrElse NotFound
11599
}
116100
}
117101

play-sample/app/controllers/Skills.scala

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import play.api.data._, Forms._, validation.Constraints._
55

66
import org.json4s._, ext.JodaTimeSerializers
77
import com.github.tototoshi.play2.json4s.native._
8+
9+
import scala.concurrent.Future
810
import scala.concurrent.ExecutionContext.Implicits.global
911

1012
import models._
@@ -13,19 +15,15 @@ object Skills extends Controller with Json4s {
1315

1416
implicit val formats = DefaultFormats ++ JodaTimeSerializers.all
1517

16-
def all = Action {
17-
Async {
18-
Skill.findAll.map(skills => Ok(Extraction.decompose(skills)))
19-
}
18+
def all = Action.async {
19+
Skill.findAll.map(skills => Ok(Extraction.decompose(skills)))
2020
}
2121

22-
def show(id: Long) = Action {
23-
Async {
24-
Skill.find(id).map { skillOpt =>
25-
skillOpt map { skill =>
26-
Ok(Extraction.decompose(skill))
27-
} getOrElse NotFound
28-
}
22+
def show(id: Long) = Action.async {
23+
Skill.find(id).map { skillOpt =>
24+
skillOpt map { skill =>
25+
Ok(Extraction.decompose(skill))
26+
} getOrElse NotFound
2927
}
3028
}
3129

@@ -35,27 +33,21 @@ object Skills extends Controller with Json4s {
3533
mapping("name" -> text.verifying(nonEmpty))(SkillForm.apply)(SkillForm.unapply)
3634
)
3735

38-
def create = Action { implicit req =>
36+
def create = Action.async { implicit req =>
3937
skillForm.bindFromRequest.fold(
40-
formWithErrors => BadRequest("invalid parameters"),
41-
form => {
42-
Async {
43-
Skill.create(name = form.name).map { skill =>
44-
Created.withHeaders(LOCATION -> s"/skills/${skill.id}")
45-
}
46-
}
38+
formWithErrors => Future.successful(BadRequest("invalid parameters")),
39+
form => Skill.create(name = form.name).map { skill =>
40+
Created.withHeaders(LOCATION -> s"/skills/${skill.id}")
4741
}
4842
)
4943
}
5044

51-
def delete(id: Long) = Action {
52-
Async {
53-
Skill.find(id).map { skillOpt =>
54-
skillOpt map { skill =>
55-
skill.destroy()
56-
NoContent
57-
} getOrElse NotFound
58-
}
45+
def delete(id: Long) = Action.async {
46+
Skill.find(id).map { skillOpt =>
47+
skillOpt map { skill =>
48+
skill.destroy()
49+
NoContent
50+
} getOrElse NotFound
5951
}
6052
}
6153

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
drop table if exists programmer;
2+
create sequence programmer_id_seq start with 1;
3+
create table programmer (
4+
id bigint not null default nextval('programmer_id_seq') primary key,
5+
name varchar(255) not null,
6+
company_id bigint,
7+
created_timestamp timestamp not null,
8+
deleted_timestamp timestamp
9+
);
10+
11+
drop table if exists company;
12+
create sequence company_id_seq start with 1;
13+
create table company (
14+
id bigint not null default nextval('company_id_seq') primary key,
15+
name varchar(255) not null,
16+
url varchar(255),
17+
created_at timestamp not null,
18+
deleted_at timestamp
19+
);
20+
21+
drop table if exists skill;
22+
create sequence skill_id_seq start with 1;
23+
create table skill (
24+
id bigint not null default nextval('skill_id_seq') primary key,
25+
name varchar(255) not null,
26+
created_at timestamp not null,
27+
deleted_at timestamp
28+
);
29+
30+
drop table if exists programmer_skill;
31+
create table programmer_skill (
32+
programmer_id bigint not null,
33+
skill_id bigint not null,
34+
primary key(programmer_id, skill_id)
35+
);
36+
37+
insert into company (name, url, created_at) values ('Typesafe', 'http://typesafe.com/', current_timestamp);
38+
insert into company (name, url, created_at) values ('Oracle', 'http://www.oracle.com/', current_timestamp);
39+
insert into company (name, url, created_at) values ('Google', 'http://www.google.com/', current_timestamp);
40+
insert into company (name, url, created_at) values ('Microsoft', 'http://www.microsoft.com/', current_timestamp);
41+
42+
insert into skill (name, created_at) values ('Scala', current_timestamp);
43+
insert into skill (name, created_at) values ('Java', current_timestamp);
44+
insert into skill (name, created_at) values ('Ruby', current_timestamp);
45+
insert into skill (name, created_at) values ('MySQL', current_timestamp);
46+
insert into skill (name, created_at) values ('PostgreSQL', current_timestamp);
47+
48+
49+
insert into programmer (name, company_id, created_timestamp) values ('Alice', 1, current_timestamp);
50+
insert into programmer (name, company_id, created_timestamp) values ('Bob', 2, current_timestamp);
51+
insert into programmer (name, company_id, created_timestamp) values ('Chris', 1, current_timestamp);
52+
53+
insert into programmer_skill values (1, 1);
54+
insert into programmer_skill values (1, 2);
55+
insert into programmer_skill values (2, 2);
56+

play-sample/conf/play.plugins

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
888:scalikejdbc.async.PlayPlugin
1+
666:com.github.tototoshi.play2.flyway.Plugin
2+
777:scalikejdbc.async.PlayPlugin
23

0 commit comments

Comments
 (0)