-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2.添加了mysql-otp的支持 3.添加了数据库连接池poolboy 4.目前添加的东西很多,项目结构有点乱,后续整理
- Loading branch information
Showing
50 changed files
with
37,021 additions
and
5,859 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]). |
Submodule mysql
added at
5ad838
Submodule poolboy
added at
3bb48a
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.