How to configure transactor in doobie? - mysql

Recently I started learning doobie but I couldn't create a hikari transactor without error. I'm using mysql, Intellij-Idea.
This is my build.sbt file
name := "doobie"
version := "0.1"
//scalaVersion := "2.13.1"
scalacOptions += "-Ypartial-unification" // 2.11.9+
libraryDependencies ++= {
lazy val doobieVersion = "0.8.4"
Seq(
"org.tpolecat" %% "doobie-core" % doobieVersion,
"org.tpolecat" %% "doobie-h2" % doobieVersion,
"org.tpolecat" %% "doobie-hikari" % doobieVersion,
"org.tpolecat" %% "doobie-quill" % doobieVersion,
"org.tpolecat" %% "doobie-specs2" % doobieVersion,
"org.tpolecat" %% "doobie-scalatest" % doobieVersion % "test",
"mysql" % "mysql-connector-java" % "8.0.17",
"org.slf4j" % "slf4j-api" % "1.7.5",
"ch.qos.logback" % "logback-classic" % "1.0.9"
)
}
resolvers ++= Seq(
"Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
)
This is my Connection.scala file
import cats.effect.IO
import com.zaxxer.hikari.{HikariConfig, HikariDataSource}
import doobie.hikari.HikariTransactor
trait Connection {
val config = new HikariConfig()
config.setJdbcUrl("jdbc:mysql://localhost:quill_demo")
config.setUsername("admin")
config.setPassword("password")
config.setMaximumPoolSize(5)
val transactor: IO[HikariTransactor[IO]] =
IO.pure(HikariTransactor.apply[IO](new HikariDataSource(config)))
}
The problem is in above file IO.pure(HikariTransactor.apply[IO](new HikariDataSource(config))) statement gives error. Here 3 of last closed braces gives 3 errors as below.
No implicit arguments of type: ContextShift[IO]
Unspecified value parameters: connectEC: ExecutionContext, transactEC: ExecutionContext
No implicits found for parameter evidence$2: ContextShift[IO]
All I want to know, How to do this correctly.

Try to add the following import and implicit
import scala.concurrent.ExecutionContext
implicit val cs = IO.contextShift(ExecutionContext.global)

After I change the versions of dependencies as follows, I could solve all errors.
name := "doobie"
version := "0.1"
//scalaVersion := "2.13.1"
scalacOptions += "-Ypartial-unification"
libraryDependencies ++= {
lazy val doobieVersion = "0.5.4"
Seq(
"org.tpolecat" %% "doobie-core" % doobieVersion,
"org.tpolecat" %% "doobie-h2" % doobieVersion,
"org.tpolecat" %% "doobie-hikari" % doobieVersion,
"org.tpolecat" %% "doobie-quill" % doobieVersion,
"org.tpolecat" %% "doobie-specs2" % doobieVersion,
"org.tpolecat" %% "doobie-scalatest" % doobieVersion % "test",
"mysql" % "mysql-connector-java" % "5.1.34",
"org.slf4j" % "slf4j-api" % "1.7.5",
"ch.qos.logback" % "logback-classic" % "1.0.9"
)
}
resolvers ++= Seq(
"Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
)

Related

Octave: invalid call to a script

I am trying to call to a script, and I am getting an error message. Please help.
The following is what I am trying to run in Octave:
%%% May 23, 2016
%%% Potential Fields for Robot Path Planning
%
%
% Initially proposed for real-time collision avoidance [Khatib 1986].
% Hundreds of papers published on APF
% A potential field is a scalar function over the free space.
% To navigate, the robot applies a force proportional to the
% negated gradient of the potential field.
% A navigation function is an ideal potential field
clc
close all
clear
%% Defining environment variables
startPos = [5,5];
goalPos = [90, 95];
obs1Pos = [50, 50];
obsRad = 10;
goalR = 0.2; % The radius of the goal
goalS = 20; % The spread of attraction of the goal
obsS = 30; % The spread of repulsion of the obstacle
alpha = 0.8; % Strength of attraction
beta = 0.6; % Strength of repulsion
%% Carry out the Potential Field Math as follows:
u = zeros(100, 100);
v = zeros(100, 100);
testu = zeros(100, 100);
testv = zeros(100, 100);
for x = 1:1:100
for y = 1:1:100
[uG, vG] = GoalDelta(x, y, goalPos(1), goalPos(2), goalR, goalS, alpha);
[uO, vO] = ObsDelta(x, y, obs1Pos(2), obs1Pos(1), obsRad, obsS, beta);
xnet = uG + uO;
ynet = vG + vO;
vspeed = sqrt(xnet^2 + ynet^2);
theta = atan2(ynet,xnet);
u(x,y) = vspeed*cos(theta);
v(x,y) = vspeed*sin(theta);
% hold on
end
end
%%
[X,Y] = meshgrid(1:1:100,1:1:100);
figure
quiver(X, Y, u, v, 3)
%% Defining the grid
% Plotting the obstacles
circles(obs1Pos(1),obs1Pos(2),obsRad, 'facecolor','red')
axis square
hold on % Plotting start position
circles(startPos(1),startPos(2),2, 'facecolor','green')
hold on % Plotting goal position
circles(goalPos(1),goalPos(2),2, 'facecolor','yellow')
%% Priting of the path
currentPos = startPos;
x = 0;
while sqrt((goalPos(1)-currentPos(1))^2 + (goalPos(2)-currentPos(2))^2) > 1
tempPos = currentPos + [u(currentPos(1),currentPos(2)), v(currentPos(1),currentPos(2))]
currentPos = round(tempPos)
hold on
plot(currentPos(1),currentPos(2),'-o', 'MarkerFaceColor', 'black')
pause(0.5)
end
The following is the error message I am getting:
error: invalid call to script C:\Users\MyComputer\Downloads\circles.m
error: called from
circles
ECE8743_PotentialFields_Obstacle_1 at line 59 column 1
>>
Here is circles.m:
function [ h ] = circles(x,y,r,varargin)
% h = circles(x,y,r,varargin) plots circles of radius r at points x and y.
% x, y, and r can be scalars or N-D arrays.
%
% Chad Greene, March 2014. Updated August 2014.
% University of Texas Institute for Geophysics.
%
%% Syntax
% circles(x,y,r)
% circles(...,'points',numberOfPoints)
% circles(...,'rotation',degreesRotation)
% circles(...,'ColorProperty',ColorValue)
% circles(...,'LineProperty',LineValue)
% h = circles(...)
%
%% Description
%
% circles(x,y,r) plots circle(s) of radius or radii r centered at points given by
% x and y. Inputs x, y, and r may be any combination of scalar,
% vector, or 2D matrix, but dimensions of all nonscalar inputs must agree.
%
% circles(...,'points',numberOfPoints) allows specification of how many points to use
% for the outline of each circle. Default value is 1000, but this may be
% increased to increase plotting resolution. Or you may specify a small
% number (e.g. 4 to plot a square, 5 to plot a pentagon, etc.).
%
% circles(...,'rotation',degreesRotation) rotates the shape by a given
% degreesRotation, which can be a scalar or a matrix. This is useless for
% circles, but may be desired for polygons with a discernible number of corner points.
%
% circles(...,'ColorProperty',ColorValue) allows declaration of
% 'facecolor' or 'facealpha'
% as name-value pairs. Try declaring any fill property as name-value pairs.
%
% circles(...,'LineProperty',LineValue) allows declaration of 'edgecolor',
% 'linewidth', etc.
%
% h = circles(...) returns the handle(s) h of the plotted object(s).
%
%
%% EXAMPLES:
%
% Example 1:
% circles(5,10,3)
%
% % Example 2:
% x = 2:7;
% y = [5,15,12,25,3,18];
% r = [3 4 5 5 7 3];
% figure
% circles(x,y,r)
%
% % Example 3:
% figure
% circles(1:10,5,2)
%
% % Example 4:
% figure
% circles(5,15,1:5,'facecolor','none')
%
% % Example 5:
% figure
% circles(5,10,3,'facecolor','green')
%
% % Example 6:
% figure
% h = circles(5,10,3,'edgecolor',[.5 .2 .9])
%
% % Example 7:
% lat = repmat((10:-1:1)',1,10);
% lon = repmat(1:10,10,1);
% r = .4;
% figure
% h1 = circles(lon,lat,r,'linewidth',4,'edgecolor','m','facecolor',[.6 .4 .8]);
% hold on;
% h2 = circles(1:.5:10,((1:.5:10).^2)/10,.12,'edgecolor','k','facecolor','none');
% axis equal
%
% % Example 8: Circles have corners
% This script approximates circles with 1000 points. If all those points
% are too complex for your Pentium-II, you can reduce the number of points
% used to make each circle. If 1000 points is not high enough resolution,
% you can increase the number of points. Or if you'd like to draw
% triangles or squares, or pentagons, you can significantly reduce the
% number of points. Let's try drawing a stop sign:
%
% figure
% h = circles(1,1,10,'points',8,'color','red');
% axis equal
% % and we see that our stop sign needs to be rotated a little bit, so we'll
% % delete the one we drew and try again:
% delete(h)
% h = circles(1,1,10,'points',8,'color','red','rot',45/2);
% text(1,1,'STOP','fontname','helvetica CY',...
% 'horizontalalignment','center','fontsize',140,...
% 'color','w','fontweight','bold')
%
% figure
% circles([1 3 5],2,1,'points',4,'rot',[0 45 35])
%
%
% TIPS:
% 1. Include the name-value pair 'facecolor','none' to draw outlines
% (non-filled) circles.
%
% 2. Follow the circles command with axis equal to fix distorted circles.
%
% See also: fill, patch, and scatter.
%% Check inputs:
assert(isnumeric(x),'Input x must be numeric.')
assert(isnumeric(y),'Input y must be numeric.')
assert(isnumeric(r),'Input r must be numeric.')
if ~isscalar(x) && ~isscalar(y)
assert(numel(x)==numel(y),'If neither x nor y is a scalar, their dimensions must match.')
end
if ~isscalar(x) && ~isscalar(r)
assert(numel(x)==numel(r),'If neither x nor r is a scalar, their dimensions must match.')
end
if ~isscalar(r) && ~isscalar(y)
assert(numel(r)==numel(y),'If neither y nor r is a scalar, their dimensions must match.')
end
%% Parse inputs:
% Define number of points per circle:
tmp = strcmpi(varargin,'points')|strcmpi(varargin,'NOP')|strcmpi(varargin,'corners')|...
strncmpi(varargin,'vert',4);
if any(tmp)
NOP = varargin{find(tmp)+1};
tmp(find(tmp)+1)=1;
varargin = varargin(~tmp);
else
NOP = 1000; % 1000 points on periphery by default
end
% Define rotation
tmp = strncmpi(varargin,'rot',3);
if any(tmp)
rotation = varargin{find(tmp)+1};
assert(isnumeric(rotation)==1,'Rotation must be numeric.')
rotation = rotation*pi/180; % converts to radians
tmp(find(tmp)+1)=1;
varargin = varargin(~tmp);
else
rotation = 0; % no rotation by default.
end
% Be forgiving if the user enters "color" instead of "facecolor"
tmp = strcmpi(varargin,'color');
if any(tmp)
varargin{tmp} = 'facecolor';
end
%% Begin operations:
% Make inputs column vectors:
x = x(:);
y = y(:);
r = r(:);
rotation = rotation(:);
% Determine how many circles to plot:
numcircles = max([length(x) length(y) length(r) length(rotation)]);
% Create redundant arrays to make the plotting loop easy:
if length(x)<numcircles
x(1:numcircles) = x;
end
if length(y)<numcircles
y(1:numcircles) = y;
end
if length(r)<numcircles
r(1:numcircles) = r;
end
if length(rotation)<numcircles
rotation(1:numcircles) = rotation;
end
% Define an independent variable for drawing circle(s):
t = 2*pi/NOP*(1:NOP);
% Query original hold state:
holdState = ishold;
hold on;
% Preallocate object handle:
h = NaN(size(x));
% Plot circles singly:
for n = 1:numcircles
h(n) = fill(x(n)+r(n).*cos(t+rotation(n)), y(n)+r(n).*sin(t+rotation(n)),'',varargin{:});
end
% Return to original hold state:
if ~holdState
hold off
end
% Delete object handles if not requested by user:
if nargout==0
clear h
end
end
What am I doing wrong here? How do I correct this error? I am rather new to Octave and Matlab, so any help is greatly appreciated.
this is the first post after pasting the error so maybe it'll help anyone later:
in my case pasting the script into a function worked out!
function retval = name_of_script(parametres)
%your script
endfunction

How to decode missing json array as empty List with circe

For example, we have some case class
case class Foo(a: Int, b: List[String])
And we want to deserialize instance of Foo from json {"a": 1} replacing missing b array with Nil
We can create custom decoder for such behavior
implicit val fooDecoder: Decoder[Foo] = (c: HCursor) =>
for {
a <- c.downField("a").as[Int]
b <- c.downField("b").as[Option[List[String]]
} yield Foo(a, b.getOrElse(Nil))
But, unfortunately, the created this way decoder doesn't accumulate all decoding failures.
Is there any way to create decoder with failures accumulation or any way to replace standard list deserialization behavior in circe?
Try providing default value b: List[String] = Nil using circe-generic-extras like so
import io.circe.parser._
import io.circe.generic.extras.Configuration
import io.circe.generic.extras.auto._
implicit val config: Configuration = Configuration.default.withDefaults
case class Foo(a: Int, b: List[String] = Nil)
val raw = """{"a": 1}"""
decode[Foo](raw) // res0: Either[io.circe.Error,Foo] = Right(Foo(1,List()))
where
libraryDependencies ++= Seq(
"io.circe" %% "circe-core" % "0.12.0-M3",
"io.circe" %% "circe-parser" % "0.12.0-M3",
"io.circe" %% "circe-generic-extras" % "0.12.0-M3",
"io.circe" %% "circe-generic" % "0.12.0-M3"
)
You can also use .map(_.getOrElse(List.empty)) as well
implicit val fooDecoder: Decoder[Foo] = (c: HCursor) =>
for {
a <- c.downField("a").as[Int]
b <- c.downField("b").as[Option[List[String]].map(_.getOrElse(List.empty))
} yield Foo(a, b)

JSON4S error at extract[T]

i am using json4s to extract data according to case class but i am getting a "unknown error". My scala version is 2.10.2 and Json4S is 3.2.10
My code look like:
import org.json4s._
import org.json4s.jackson.JsonMethods._
implicit val formats = org.json4s.DefaultFormats
case class Person(name: String, age: Int)
class user{
def add(){
val json="""{"1":{"name":"user1", "age":16}}"""
print(parse(json).extract[Map[String,Person]])
}
}
Could any one suggest What i am missing here?
I tried based on the suggestion given here:
JSON4S unknown error
https://github.com/json4s/json4s/issues/125
But I still get following error:
java.lang.NoSuchMethodError: scala.collection.immutable.$colon$colon.hd$1()Ljava/lang/Object;
at org.json4s.MonadicJValue.$bslash(MonadicJValue.scala:18)
at org.json4s.Extraction$ClassInstanceBuilder$$anonfun$14.apply(Extraction.scala:463)
at org.json4s.Extraction$ClassInstanceBuilder$$anonfun$14.apply(Extraction.scala:463)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at org.json4s.Extraction$ClassInstanceBuilder.org$json4s$Extraction$ClassInstanceBuilder$$instantiate(Extraction.scala:451)
at org.json4s.Extraction$ClassInstanceBuilder$$anonfun$result$6.apply(Extraction.scala:491)
at org.json4s.Extraction$ClassInstanceBuilder$$anonfun$result$6.apply(Extraction.scala:488)
at org.json4s.Extraction$.org$json4s$Extraction$$customOrElse(Extraction.scala:500)
at org.json4s.Extraction$ClassInstanceBuilder.result(Extraction.scala:488)
at org.json4s.Extraction$.extract(Extraction.scala:332)
at org.json4s.Extraction$$anonfun$extract$5.apply(Extraction.scala:316)
at org.json4s.Extraction$$anonfun$extract$5.apply(Extraction.scala:316)
at scala.collection.immutable.List.map(List.scala:273)
at org.json4s.Extraction$.extract(Extraction.scala:316)
at org.json4s.Extraction$.extract(Extraction.scala:42)
at org.json4s.ExtractableJsonAstNode.extract(ExtractableJsonAstNode.scala:21)
at com.czechscala.blank.HttpMethods.parseJsonResponse(HttpMethods.scala:87)
at com.czechscala.blank.HttpMethods.getRequestFunction(HttpMethods.scala:184)
at com.czechscala.blank.Hello$$anonfun$sendParallelRequests$1$$anonfun$apply$mcVI$sp$1$$anonfun$apply$mcV$sp$1.apply$mcV$sp(Hello.scala:68)
at com.czechscala.blank.Hello$$anonfun$sendParallelRequests$1$$anonfun$apply$mcVI$sp$1$$anonfun$apply$mcV$sp$1.apply(Hello.scala:64)
at com.czechscala.blank.Hello$$anonfun$sendParallelRequests$1$$anonfun$apply$mcVI$sp$1$$anonfun$apply$mcV$sp$1.apply(Hello.scala:64)
at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$2$$anon$4.block(ExecutionContextImpl.scala:48)
at scala.concurrent.forkjoin.ForkJoinPool.managedBlock(ForkJoinPool.java:3640)
at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$2.blockOn(ExecutionContextImpl.scala:45)
at scala.concurrent.package$.blocking(package.scala:123)
at com.czechscala.blank.Hello$$anonfun$sendParallelRequests$1$$anonfun$apply$mcVI$sp$1.apply$mcV$sp(Hello.scala:64)
at com.czechscala.blank.Hello$$anonfun$sendParallelRequests$1$$anonfun$apply$mcVI$sp$1.apply(Hello.scala:64)
at com.czechscala.blank.Hello$$anonfun$sendParallelRequests$1$$anonfun$apply$mcVI$sp$1.apply(Hello.scala:64)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
at scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
java.lang.NoSuchMethodError: scala.collection.immutable.$colon$colon.hd$1()Ljava/lang/Object;
at org.json4s.MonadicJValue.$bslash(MonadicJValue.scala:18)
at org.json4s.Extraction$ClassInstanceBuilder$$anonfun$14.apply(Extraction.scala:463)
at org.json4s.Extraction$ClassInstanceBuilder$$anonfun$14.apply(Extraction.scala:463)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at org.json4s.Extraction$ClassInstanceBuilder.org$json4s$Extraction$ClassInstanceBuilder$$instantiate(Extraction.scala:451)
at org.json4s.Extraction$ClassInstanceBuilder$$anonfun$result$6.apply(Extraction.scala:491)
at org.json4s.Extraction$ClassInstanceBuilder$$anonfun$result$6.apply(Extraction.scala:488)
at org.json4s.Extraction$.org$json4s$Extraction$$customOrElse(Extraction.scala:500)
at org.json4s.Extraction$ClassInstanceBuilder.result(Extraction.scala:488)
at org.json4s.Extraction$.extract(Extraction.scala:332)
at org.json4s.Extraction$$anonfun$extract$5.apply(Extraction.scala:316)
at org.json4s.Extraction$$anonfun$extract$5.apply(Extraction.scala:316)
at scala.collection.immutable.List.map(List.scala:273)
at org.json4s.Extraction$.extract(Extraction.scala:316)
at org.json4s.Extraction$.extract(Extraction.scala:42)
at org.json4s.ExtractableJsonAstNode.extract(ExtractableJsonAstNode.scala:21)
at com.czechscala.blank.HttpMethods.parseJsonResponse(HttpMethods.scala:87)
at com.czechscala.blank.HttpMethods.getRequestFunction(HttpMethods.scala:184)
at com.czechscala.blank.Hello$$anonfun$sendParallelRequests$1$$anonfun$apply$mcVI$sp$1$$anonfun$apply$mcV$sp$1.apply$mcV$sp(Hello.scala:68)
at com.czechscala.blank.Hello$$anonfun$sendParallelRequests$1$$anonfun$apply$mcVI$sp$1$$anonfun$apply$mcV$sp$1.apply(Hello.scala:64)
at com.czechscala.blank.Hello$$anonfun$sendParallelRequests$1$$anonfun$apply$mcVI$sp$1$$anonfun$apply$mcV$sp$1.apply(Hello.scala:64)
at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$2$$anon$4.block(ExecutionContextImpl.scala:48)
at scala.concurrent.forkjoin.ForkJoinPool.managedBlock(ForkJoinPool.java:3640)
at scala.concurrent.impl.ExecutionContextImpl$DefaultThreadFactory$$anon$2.blockOn(ExecutionContextImpl.scala:45)
at scala.concurrent.package$.blocking(package.scala:123)
at com.czechscala.blank.Hello$$anonfun$sendParallelRequests$1$$anonfun$apply$mcVI$sp$1.apply$mcV$sp(Hello.scala:64)
at com.czechscala.blank.Hello$$anonfun$sendParallelRequests$1$$anonfun$apply$mcVI$sp$1.apply(Hello.scala:64)
at com.czechscala.blank.Hello$$anonfun$sendParallelRequests$1$$anonfun$apply$mcVI$sp$1.apply(Hello.scala:64)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
at scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
My build.sbt:
name := "blank"
version := "1.0-SNAPSHOT"
scalaVersion := "2.10.2"
libraryDependencies ++= Seq (
"org.scalatest" % "scalatest_2.10" % "1.9.1" % "test"
)
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.1.2"
)
libraryDependencies ++= Seq(
"net.databinder" %% "dispatch" % "0.8.10"
)
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-actors" % "2.10.2"
)
libraryDependencies ++= Seq(
"net.databinder" %% "dispatch-core" % "0.8.10"
)
libraryDependencies ++= Seq(
"net.databinder" %% "dispatch-futures" % "0.8.10"
)
libraryDependencies ++= Seq(
"net.databinder" %% "dispatch-nio" % "0.8.10"
)
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % "1.6.4",
"org.slf4j" % "slf4j-simple" % "1.6.4"
)
libraryDependencies ++= Seq(
"org.json4s" %% "json4s-core" % "3.2.10",
"org.json4s" %% "json4s-native" % "3.2.10",
"org.json4s" %% "json4s-jackson" % "3.2.10",
"net.databinder" %% "unfiltered-netty" % "0.8.0" % "test",
"net.databinder.dispatch" % "dispatch-json4s-native_2.11" % "0.11.1"
)
libraryDependencies ++= Seq(
"io.argonaut" %% "argonaut" % "6.0.4"
)
initialCommands := "import dispatch._"
This modified json is working for me
val json="""{"1":{"name":"user1", "age":16}}"""
age is in quotes and taking quotes for 16. age is defined as int.
When I replicated your build.sbt, it seems there is two conflicting version of json4s related libraiers are getting loaded. One version mentioned here for the
"org.json4s" %% "json4s-core" % "3.2.10",
"org.json4s" %% "json4s-native" % "3.2.10",
"org.json4s" %% "json4s-jackson" % "3.2.10",
And the other version mentioned from this line
"net.databinder.dispatch" ...... "..._2.11",
which is pulling the json4s for the scala 2.11 version.
Changing the netbinder version from "_2.11" to "_2.10" seems to be building fine.

How do I run JUnit 4.11 test cases with SBT?

I have the following in build.sbt:
libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test"
libraryDependencies += "junit" % "junit" % "4.11" % "test"
I noticed that junit-interface 0.10 depends on junit-dep 4.10. This makes it impossible to compile tests that use assertNotEquals which was introduced in junit 4.11.
How do I run JUnit 4.11 test cases with SBT?
I would do this:
libraryDependencies ++= Seq(
"junit" % "junit" % "4.11" % Test,
"com.novocode" % "junit-interface" % "0.11" % Test
exclude("junit", "junit-dep")
)
By excluding what we don't desire, it doesn't interfere. This doesn't depend on ordering.
Use junit-interface 0.11 to avoid the dependency on junit-dep:
libraryDependencies += "junit" % "junit" % "4.12" % "test"
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"
UPDATE: junit-interface 0.11 makes this reliable by depending on junit rather than junit-dep.

erlang-mysql-driver source code, why little endianness to fetch the result

I'm new to erlang and studying erlang-mysql-driver. Can anyone help to make me understand why little endianness here when parsing the binary in function "get_lcb"?
Following is the code in mysql_conn.erl
%%--------------------------------------------------------------------
%% Function: get_query_response(LogFun, RecvPid)
%% LogFun = undefined | function() with arity 3
%% RecvPid = pid(), mysql_recv process
%% Version = integer(), Representing MySQL version used
%% Descrip.: Wait for frames until we have a complete query response.
%% Returns : {data, #mysql_result}
%% {updated, #mysql_result}
%% {error, #mysql_result}
%% FieldInfo = list() of term()
%% Rows = list() of [string()]
%% AffectedRows = int()
%% Reason = term()
%%--------------------------------------------------------------------
get_query_response(LogFun, RecvPid, Version) ->
case do_recv(LogFun, RecvPid, undefined) of
{ok, Packet, _} ->
{Fieldcount, Rest} = get_lcb(Packet),
case Fieldcount of
0 ->
%% No Tabular data
<<AffectedRows:8, Rest2/binary>> = Rest,
io:format("Rest2=~p~n", [Rest2]),
{InsertId, _} = get_lcb(Rest2),
io:format("InsertId=~p~n", [InsertId]),
{updated, #mysql_result{affectedrows=AffectedRows, insertid=InsertId}};
255 ->
<<_Code:16/little, Message/binary>> = Rest,
{error, #mysql_result{error=Message}};
_ ->
%% Tabular data received
case get_fields(LogFun, RecvPid, [], Version) of
{ok, Fields} ->
case get_rows(Fields, LogFun, RecvPid, []) of
{ok, Rows} ->
{data, #mysql_result{fieldinfo=Fields,
rows=Rows}};
{error, Reason} ->
{error, #mysql_result{error=Reason}}
end;
{error, Reason} ->
{error, #mysql_result{error=Reason}}
end
end;
{error, Reason} ->
{error, #mysql_result{error=Reason}}
end.
get_lcb(<<251:8, Rest/binary>>) ->
{null, Rest};
get_lcb(<<252:8, Value:16/little, Rest/binary>>) ->
io:format("Value=~p~n",[Value]),
io:format("Rest=~p~n",[Rest]),
{Value, Rest};
get_lcb(<<253:8, Value:24/little, Rest/binary>>) ->
{Value, Rest};
get_lcb(<<254:8, Value:32/little, Rest/binary>>) ->
{Value, Rest};
get_lcb(<<Value:8, Rest/binary>>) when Value < 251 ->
{Value, Rest};
get_lcb(<<255:8, Rest/binary>>) ->
{255, Rest}.
%%--------------------------------------------------------------------
%% Function: do_recv(LogFun, RecvPid, SeqNum)
%% LogFun = undefined | function() with arity 3
%% RecvPid = pid(), mysql_recv process
%% SeqNum = undefined | integer()
%% Descrip.: Wait for a frame decoded and sent to us by RecvPid.
%% Either wait for a specific frame if SeqNum is an integer,
%% or just any frame if SeqNum is undefined.
%% Returns : {ok, Packet, Num} |
%% {error, Reason}
%% Reason = term()
%%
%% Note : Only to be used externally by the 'mysql_auth' module.
%%--------------------------------------------------------------------
do_recv(LogFun, RecvPid, SeqNum) when is_function(LogFun);
LogFun == undefined,
SeqNum == undefined ->
receive
{mysql_recv, RecvPid, data, Packet, Num} ->
{ok, Packet, Num};
{mysql_recv, RecvPid, closed, _E} ->
{error, "mysql_recv: socket was closed"}
end;
do_recv(LogFun, RecvPid, SeqNum) when is_function(LogFun);
LogFun == undefined,
is_integer(SeqNum) ->
ResponseNum = SeqNum + 1,
receive
{mysql_recv, RecvPid, data, Packet, ResponseNum} ->
{ok, Packet, ResponseNum};
{mysql_recv, RecvPid, closed, _E} ->
{error, "mysql_recv: socket was closed"}
end.
I suppose you mean these lines: Value:16/little, Value:24/little, etc...? Well, it's because MySQL server will always fill these parts of the response packet with little-endian values - but Erlang machine by default will operate with whatever endianness is native to the CPU.