Chroma/DB.pm

filter: Statementstmt 100% 17 / 17 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 21 / 21 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Chroma.pm ↑ Summary Chroma/Tenant.pm »
1 package WebService::Chroma::DB;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use MooX::ValidateSubs;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use WebService::Chroma::Collection;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Types::Standard qw/Str Int ArrayRef HashRef ScalarRef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 validate_subs (
10 create_collection => {
11 params => {
12 name => [Str],
13 configuration => [HashRef, 1],
14 metadata => [HashRef, 1],
15 get_or_create => [ScalarRef, 1]
16 }
17 },
18 get_collections => {
19 params => {
20 limit => [Int, 1],
21 offset => [Int, 1]
22 }
23 },
24 get_collection => {
25 params => {
26 name => [Str],
27 }
28 },
29 delete_collection => {
30 params => {
31 name => [Str],
32 }
33 },
34 count_collections => {
35 params => { }
36 }
37 );
38  
39 1 has ua => (
40 is => 'ro',
41 required => 1,
42 );
43  
44 1 has tenant => (
45 is => 'ro',
46 required => 1,
47 );
48  
49 1 has name => (
50 is => 'ro',
51 required => 1,
52 );
53  
54  
55 sub create_collection {
56 my ($self, %data) = @_;
57  
58 my $collection = $self->ua->post(
59 url => sprintf('/api/v2/tenants/%s/databases/%s/collections', $self->tenant, $self->name),
60 data => \%data
61 );
62  
63 return WebService::Chroma::Collection->new(
64 ua => $self->ua,
65 tenant => $self->tenant,
66 db => $self->name,
67 %{$collection}
68 );
69 }
70  
71 sub get_collections {
72 my ($self, %data) = @_;
73 my $collections = $self->ua->get(
74 url => sprintf('/api/v2/tenants/%s/databases/%s/collections', $self->tenant, $self->name),
75 data => \%data
76 );
77 return [map {
78 WebService::Chroma::Collection->new(
79 ua => $self->ua,
80 tenant => $self->tenant,
81 db => $self->name,
82 %{$_}
83 );
84 } @{$collections}]
85 }
86  
87 sub get_collection {
88 my ($self, %data) = @_;
89  
90 my $collection = $self->ua->get(
91 url => sprintf('/api/v2/tenants/%s/databases/%s/collections/%s', $self->tenant, $self->name, $data{name}),
92 );
93
94 return WebService::Chroma::Collection->new(
95 ua => $self->ua,
96 tenant => $self->tenant,
97 db => $self->name,
98 %{$collection}
99 );
100 }
101  
102  
103 sub delete_collection {
104 my ($self, %data) = @_;
105  
106 my $collection = $self->ua->delete(
107 url => sprintf('/api/v2/tenants/%s/databases/%s/collections/%s', $self->tenant, $self->name, $data{name}),
108 );
109  
110 return $collection;
111 }
112  
113 sub count_collections {
114 my ($self, %data) = @_;
115 return $self->ua->get(
116 url => sprintf('/api/v2/tenants/%s/databases/%s/collections_count', $self->tenant, $self->name),
117 );
118 }
119  
120  
121  
122 1 1;
123  
124 __END__
« Chroma.pm ↑ Summary Chroma/Tenant.pm »