AnyEvent-Groonga

 view release on metacpan or  search on metacpan

t/04_tut.t  view on Meta::CPAN

use strict;
use warnings;
use lib '../lib';
use AnyEvent::Groonga;
use Test::More;
use FindBin;
use File::Spec;

_cleanup();

my $g = AnyEvent::Groonga->new( debug => 0 );
my $groonga_path = $g->groonga_path;
my $test_database_path
    = File::Spec->catfile( $FindBin::RealBin, "data", "test.db" );

unless ( $groonga_path and -e $groonga_path ) {
    plan skip_all => "groonga is not installed.";
}
else {
    plan tests => 21;
}

`$groonga_path -n $test_database_path quit`;

$g->protocol("local_db");
$g->database_path(
    File::Spec->catfile( $FindBin::RealBin, "data", "test.db" ) );

# status
my $result = $g->call("status")->recv;
is( $result->body->{uptime},         0 );
is( $result->body->{cache_hit_rate}, 0 );

# table_careate
$result = $g->call(
    table_create => {
        name     => "Site",
        flags    => "TABLE_HASH_KEY",
        key_type => "ShortText",
    }
)->recv;

is( $result->body, "true" );

# select
$result = $g->call( select => { table => "Site" } )->recv;

is( $result->hit_num, 0 );
is_deeply( $result->columns, [ '_id', '_key' ] );

# column_create
$result = $g->call(
    column_create => {
        table => "Site",
        name  => "title",
        flags => "COLUMN_SCALAR",
        type  => "ShortText",
    }
)->recv;

is( $result->body, "true" );

# table_create Terms
$result = $g->call(
    table_create => {
        name              => "Terms",
        flags             => "TABLE_PAT_KEY|KEY_NORMALIZE",
        key_type          => "ShortText",
        default_tokenizer => "TokenBigram",
    }
)->recv;



( run in 1.102 second using v1.01-cache-2.11-cpan-39bf76dae61 )