diff options
| author | Logan Hunt <loganhunt@simponic.xyz> | 2022-12-29 18:37:51 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-29 18:37:51 -0700 |
| commit | c143bb549c53f2737c41cdfce6cc2598c5489bdc (patch) | |
| tree | 33853e2a9c30ff7c670aa4ff5b73df005d6e6fec /lib/chessh/schema/player_session.ex | |
| parent | f7c2ccbe26dc808e4a7eae9a378e6c382220961a (diff) | |
| parent | 479ca815e3a1760c71e8977674434b15f94ae833 (diff) | |
| download | chessh-c143bb549c53f2737c41cdfce6cc2598c5489bdc.tar.gz chessh-c143bb549c53f2737c41cdfce6cc2598c5489bdc.zip | |
Merge pull request #1 from Simponic/erlang_ssh_server
Diffstat (limited to 'lib/chessh/schema/player_session.ex')
| -rw-r--r-- | lib/chessh/schema/player_session.ex | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/chessh/schema/player_session.ex b/lib/chessh/schema/player_session.ex new file mode 100644 index 0000000..84f15ee --- /dev/null +++ b/lib/chessh/schema/player_session.ex @@ -0,0 +1,34 @@ +defmodule Chessh.PlayerSession do + alias Chessh.Repo + use Ecto.Schema + import Ecto.{Query, Changeset} + + schema "player_sessions" do + field(:login, :utc_datetime) + + belongs_to(:node, Chessh.Node, type: :string) + belongs_to(:player, Chessh.Player) + end + + def changeset(player_session, attrs) do + player_session + |> cast(attrs, [:login]) + end + + def concurrent_sessions(player) do + Repo.aggregate( + from(p in Chessh.PlayerSession, + where: p.player_id == ^player.id + ), + :count + ) + end + + def delete_all_on_node(node_id) do + Repo.delete_all( + from(p in Chessh.PlayerSession, + where: p.node_id == ^node_id + ) + ) + end +end |
