Skip to content

Commit

Permalink
1.项目可以打包发布了
Browse files Browse the repository at this point in the history
2.添加了mysql-otp的支持
3.添加了数据库连接池poolboy
4.目前添加的东西很多,项目结构有点乱,后续整理
  • Loading branch information
MySixGod committed Jul 13, 2017
1 parent a1de41f commit eba2595
Show file tree
Hide file tree
Showing 50 changed files with 37,021 additions and 5,859 deletions.
1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified .rebar/erlcinfo
Binary file not shown.
Binary file added apps/example/.rebar/erlcinfo
Binary file not shown.
21 changes: 21 additions & 0 deletions apps/example/ebin/example.app
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{application, example, [
{description, "An example application"},
{vsn, "1.5.1"},
{applications, [kernel, stdlib, sasl]},
{modules, [example, example_worker,poolboy,poolboy_sup,poolboy_worker]},
{registered, [example]},
{mod, {example, []}},
{env, [
{pools, [
{pool1, [
{size, 10},
{max_overflow, 20}
], [
{hostname, "127.0.0.1"},
{database, "hello"},
{username, "root"},
{password, "cwtborn123"}
]}
]}
]}
]}.
Binary file added apps/example/ebin/example.beam
Binary file not shown.
Binary file added apps/example/ebin/example_worker.beam
Binary file not shown.
16 changes: 16 additions & 0 deletions apps/example/example.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="ERLANG_MODULE" version="4">
<component name="FacetManager">
<facet type="erlang" name="Erlang">
<configuration />
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="Erlang 19" jdkType="Erlang SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
46 changes: 46 additions & 0 deletions apps/example/src/example.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
%%%-------------------------------------------------------------------
%%% @author cwt
%%% @copyright (C) 2017, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 13. 七月 2017 19:24
%%%-------------------------------------------------------------------
-module(example).
-behaviour(application).
-behaviour(supervisor).

-export([start/0, stop/0, query/2, query/3]).
-export([start/2, stop/1]).
-export([init/1]).

start() ->
application:start(?MODULE).

stop() ->
application:stop(?MODULE).

start(_Type, _Args) ->
supervisor:start_link({local, example_sup}, ?MODULE, []).

stop(_State) ->
ok.

init([]) ->
{ok, Pools} = application:get_env(example, pools),
PoolSpecs = lists:map(fun({Name, SizeArgs, WorkerArgs}) ->
PoolArgs = [{name, {local, Name}},
{worker_module, example_worker}] ++ SizeArgs,
poolboy:child_spec(Name, PoolArgs, WorkerArgs)
end, Pools),
{ok, {{one_for_one, 10, 10}, PoolSpecs}}.

query(PoolName, Sql) ->
poolboy:transaction(PoolName, fun(Worker) ->
gen_server:call(Worker, {query, Sql})
end).

query(PoolName, Stmt, Params) ->
poolboy:transaction(PoolName, fun(Worker) ->
gen_server:call(Worker, {query, Stmt, Params})
end).
53 changes: 53 additions & 0 deletions apps/example/src/example_worker.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
%%%-------------------------------------------------------------------
%%% @author cwt
%%% @copyright (C) 2017, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 13. 七月 2017 19:26
%%%-------------------------------------------------------------------
-module(example_worker).
-behaviour(gen_server).
-behaviour(poolboy_worker).

-export([start_link/1]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
code_change/3]).

-record(state, {conn}).

start_link(Args) ->
gen_server:start_link(?MODULE, Args, []).

init(Args) ->
process_flag(trap_exit, true),
Hostname = proplists:get_value(hostname, Args),
Database = proplists:get_value(database, Args),
Username = proplists:get_value(username, Args),
Password = proplists:get_value(password, Args),
%% {ok, Conn} = mysql:connect(Hostname, Username, Password, [
%% {database, Database}
%% ]),
{ok, Conn} = mysql:start_link([{host, Hostname}, {port, 3306}, {user, Username},
{password, Password}, {database, Database}]),
{ok, #state{conn = Conn}}.

handle_call({query, Sql}, _From, #state{conn = Conn} = State) ->
{reply, mysql:query(Conn, Sql), State};
handle_call({query, Stmt, Params}, _From, #state{conn = Conn} = State) ->
{reply, mysql:query(Conn, Stmt, Params), State};
handle_call(_Request, _From, State) ->
{reply, ok, State}.

handle_cast(_Msg, State) ->
{noreply, State}.

handle_info(_Info, State) ->
{noreply, State}.

terminate(_Reason, #state{conn = Conn}) ->
%% ok = mysql:close(Conn),
{ok,Conn}.

code_change(_OldVsn, State, _Extra) ->
{ok, State}.
3 changes: 3 additions & 0 deletions create.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
erl -pa ./ebin ./deps/mysql/ebin ./apps/example/ebin
pause
systools:make_script("erlang_redis",[local]).
1 change: 1 addition & 0 deletions deps/mysql
Submodule mysql added at 5ad838
1 change: 1 addition & 0 deletions deps/poolboy
Submodule poolboy added at 3bb48a
Binary file modified ebin/demo1.beam
Binary file not shown.
10 changes: 0 additions & 10 deletions ebin/erlang_otp.app

This file was deleted.

12 changes: 12 additions & 0 deletions ebin/erlang_redis.app
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{application,erlang_redis,
[{description,"a simple redis"},
{vsn,"0.1.0"},
{registered,[]},
{applications,[kernel,stdlib,mysql,example]},
{mod,{erlang_redis,[]}},
{env,[]},
{modules,[d1,demo1,erlang_redis,exception,fsm,fsm_tem,gen_sup,
mysql_test,poolboy,pushbutton,recursive,redis_app,
redis_element,redis_event,redis_event_logger,
redis_store,redis_sup,resource_discovery,sa,
simple_redis,test,test_statem,unit]}]}.
Binary file added ebin/erlang_redis.beam
Binary file not shown.
Binary file added ebin/fsm.beam
Binary file not shown.
Binary file added ebin/fsm_tem.beam
Binary file not shown.
Binary file added ebin/mysql_test.beam
Binary file not shown.
Binary file added ebin/poolboy.beam
Binary file not shown.
Binary file added ebin/pushbutton.beam
Binary file not shown.
Binary file added ebin/recursive.beam
Binary file not shown.
Binary file modified ebin/redis_store.beam
Binary file not shown.
Binary file modified ebin/resource_discovery.beam
Binary file not shown.
Binary file added ebin/test_statem.beam
Binary file not shown.
Binary file modified ebin/unit.beam
Binary file not shown.
Loading

0 comments on commit eba2595

Please sign in to comment.