Module watts_persistent_sqlite

This module implements the persistent database using an sqlite database.

Behaviours: gen_server, watts_persistent.

Description

This module implements the persistent database using an sqlite database.

Data Types

state()

state() = #state{con = undefined | esqlite:connection()}

Function Index

code_change/3do nothing, just return the old state.
create_random_uuid/1*generate a random unique uuid.
create_tables_if_needed/1*create the needed tables in the database, if needed.
credential_add/5store a credential for a user A callback from the watts_persistent behaviour.
credential_add/6*add a credential into the databas, this is the SQL implementation.
credential_get/1get a specific credential.
credential_get/2*return a specific credential.
credential_get_count/2get the number of credentials for a user at a service.
credential_get_count/3*return the number of credential the user has at the service.
credential_get_list/1get the list of credentials for a user A callback from the watts_persistent behaviour.
credential_get_list/2*return the list of credentials for a given user.
credential_remove/2remove a credential of a user A callback from the watts_persistent behaviour.
credential_remove/3*delete the credential of the user.
credential_state_unique/4*check if the state is unique for the user at the service.
handle_call/3call handling for the gen server.
handle_cast/2implement the cast handling.
handle_info/2all other messages are ignored.
init/1intialize the state of the gen_server.
initialize/0initialize the sqlite database.
is_ready/0return if the database is ready.
reconfigure/0trigger reconfiguration of the sqlite connection.
reconfigure/2*(re)start the connection to the database file.
start_link/0start the gen_server process.
stop/0stop the sqlite gen_server process.
terminate/2close sqlite database handle on termination, if needed.

Function Details

code_change/3

code_change(OldVsn::any(), State::state(), Extra::any()) -> {ok, state()}

do nothing, just return the old state.

create_random_uuid/1 *

create_random_uuid(Connection::esqlite:connection()) -> binary()

generate a random unique uuid.

create_tables_if_needed/1 *

create_tables_if_needed(Connection::esqlite:connection()) -> ok

create the needed tables in the database, if needed

credential_add/5

credential_add(UserId::binary(), ServiceId::binary(), Interface::binary(), CredState::any(), AllowNonUniqueStates::boolean()) -> {ok, CredentialID::binary()} | {error, Reason::atom()}

store a credential for a user A callback from the watts_persistent behaviour.

credential_add/6 *

credential_add(UserId::binary(), ServiceId::binary(), Interface::binary(), CredState::any(), SameStateOk::boolean(), Connect::esqlite:connection()) -> {ok, CredId::binary()} | {error, Reason::atom()}

add a credential into the databas, this is the SQL implementation.

credential_get/1

credential_get(CredId::binary()) -> {ok, watts:credential()} | {error, Reason::atom()}

get a specific credential. A callback from the watts_persistent behaviour.

credential_get/2 *

credential_get(CredentialId::binary(), Con::esqlite:connection()) -> {ok, watts:credential()} | {error, Reason::atom()}

return a specific credential

credential_get_count/2

credential_get_count(UserId::binary(), ServiceId::binary()) -> {ok, pos_integer()}

get the number of credentials for a user at a service. A callback from the watts_persistent behaviour.

credential_get_count/3 *

credential_get_count(UserId::binary(), ServiceId::binary, Con::esqlite:connection()) -> pos_integer()

return the number of credential the user has at the service.

credential_get_list/1

credential_get_list(UserId::binary()) -> {ok, [watts:credential()]}

get the list of credentials for a user A callback from the watts_persistent behaviour.

credential_get_list/2 *

credential_get_list(UserId::binary(), Con::esqlite:connection()) -> [watts:credential()]

return the list of credentials for a given user

credential_remove/2

credential_remove(UserId::binary(), CredentialId::binary()) -> ok | {error, Reason::atom()}

remove a credential of a user A callback from the watts_persistent behaviour.

credential_remove/3 *

credential_remove(UserId::binary(), CredentialId::binary(), Con::esqlite:connection()) -> ok

delete the credential of the user.

credential_state_unique/4 *

credential_state_unique(UserId::binary(), ServiceId::binary(), CredState::any(), Con::esqlite:connection()) -> {true, none} | {false, CredId::binary()}

check if the state is unique for the user at the service.

handle_call/3

handle_call(Request::any(), From::any(), State::state()) -> {reply, any(), state()}

call handling for the gen server. This function serializes the api calls and performs one after the other.

handle_cast/2

handle_cast(Msg::reconfigure | stop | any(), State::state()) -> {noreply, state()}

implement the cast handling. Supports only 'reconfigure' and 'stop'.

handle_info/2

handle_info(Info::any(), State::state()) -> {noreply, state()}

all other messages are ignored

init/1

init(X1::noparams) -> {ok, state()}

intialize the state of the gen_server.

initialize/0

initialize() -> ok

initialize the sqlite database. A callback from the watts_persistent behaviour.

is_ready/0

is_ready() -> true | {false, Reason::atom()}

return if the database is ready. A callback from the watts_persistent behaviour.

reconfigure/0

reconfigure() -> ok

trigger reconfiguration of the sqlite connection

reconfigure/2 *

reconfigure(File::string(), State::state()) -> state()

(re)start the connection to the database file.

start_link/0

start_link() -> {ok, pid()}

start the gen_server process

stop/0

stop() -> ok

stop the sqlite gen_server process

terminate/2

terminate(Reason::any(), State::state()) -> ok

close sqlite database handle on termination, if needed.


Generated by EDoc