1Apache::Session::BrowseUasbelre:C:oPnotsrtigbruetse(d3A)PpearclheD:o:cSuemsesnitoant:i:oBnrowseable::Postgres(3)
2
3
4
6 Apache::Session::Browseable::Postgres - Add index and search methods to
7 Apache::Session::Postgres
8
10 Create table with columns for indexed fields. Example for
11 Lemonldap::NG:
12
13 CREATE UNLOGGED TABLE sessions (
14 id varchar(64) not null primary key,
15 a_session text,
16 _whatToTrace text,
17 _session_kind text,
18 _utime bigint,
19 ipAddr varchar(64)
20 );
21
22 Add indexes:
23
24 CREATE INDEX uid1 ON sessions USING BTREE (_whatToTrace);
25 CREATE INDEX s1 ON sessions (_session_kind);
26 CREATE INDEX u1 ON sessions (_utime);
27 CREATE INDEX ip1 ON sessions USING BTREE (ipAddr);
28
29 Use it with Perl:
30
31 use Apache::Session::Browseable::Postgres;
32
33 my $args = {
34 DataSource => 'dbi:Pg:sessions',
35 UserName => $db_user,
36 Password => $db_pass,
37 Commit => 1,
38
39 # Choose your browseable fileds
40 Index => '_whatToTrace _session_kind _utime iAddr',
41 };
42
43 # Use it like Apache::Session
44 my %session;
45 tie %session, 'Apache::Session::Browseable::Postgres', $id, $args;
46 $session{uid} = 'me';
47 $session{mail} = 'me@me.com';
48 $session{unindexedField} = 'zz';
49 untie %session;
50
51 # Apache::Session::Browseable add some global class methods
52 #
53 # 1) search on a field (indexed or not)
54 my $hash = Apache::Session::Browseable::Postgres->searchOn( $args, 'uid', 'me' );
55 foreach my $id (keys %$hash) {
56 print $id . ":" . $hash->{$id}->{mail} . "\n";
57 }
58
59 # 2) Parse all sessions
60 # a. get all sessions
61 my $hash = Apache::Session::Browseable::Postgres->get_key_from_all_sessions();
62
63 # b. get some fields from all sessions
64 my $hash = Apache::Session::Browseable::Postgres->get_key_from_all_sessions('uid', 'mail')
65
66 # c. execute something with datas from each session :
67 # Example : get uid and mail if mail domain is
68 my $hash = Apache::Session::Browseable::Postgres->get_key_from_all_sessions(
69 sub {
70 my ( $session, $id ) = @_;
71 if ( $session->{mail} =~ /mydomain.com$/ ) {
72 return { $session->{uid}, $session->{mail} };
73 }
74 }
75 );
76 foreach my $id (keys %$hash) {
77 print $id . ":" . $hash->{$id}->{uid} . "=>" . $hash->{$id}->{mail} . "\n";
78 }
79
81 Apache::Session::Browseable provides some class methods to manipulate
82 all sessions and add the capability to index some fields to make
83 research faster.
84
85 Apache::Session::Browseable::Postgres implements it for PosqtgreSQL
86 databases.
87
89 <http://lemonldap-ng.org>, Apache::Session::Postgres
90
92 Xavier Guimard, <x.guimard@free.fr>
93
95 Copyright (C) 2009-2017 by Xavier Guimard
96 2013-2017 by Clément Oudot
97
98 This library is free software; you can redistribute it and/or modify it
99 under the same terms as Perl itself, either Perl version 5.10.1 or, at
100 your option, any later version of Perl 5 you may have available.
101
102
103
104perl v5.36.0 2023-A0p1a-c1h9e::Session::Browseable::Postgres(3)