From 922cb7dec4d0ab188cd7e39608da05b481f00f08 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 8 Nov 2010 18:51:30 +0100 Subject: [PATCH] fix replication and document it --- README | 7 +++++++ angular-server.pl | 11 +++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README b/README index 8c716ea..dd7aa13 100644 --- a/README +++ b/README @@ -25,6 +25,13 @@ At it's current stage it provides support for angular $resource get, query and $ http://angularjs.org/Service:$resource +Server also supports replication using same API which can be triggered with + + http://localhost:3000/_replicate?from=http://dpavlin.getangular.com/data/conference/ + +Replication is currently good only for initial import of data since it doesn't +support incremental replication and dies if data is allready present. + Installation: diff --git a/angular-server.pl b/angular-server.pl index 221f60d..4471a06 100755 --- a/angular-server.pl +++ b/angular-server.pl @@ -64,7 +64,6 @@ get '/_replicate' => sub { if ( my $from = $self->param('from') ) { my $got = $self->client->get( $from )->res->json; warn "# from $from ",dump($got); - _render_jsonp( $self, $got ); my $database = $got->{name}; my $entities = $got->{entities}; @@ -74,11 +73,15 @@ get '/_replicate' => sub { my $url = $from; $url =~ s{/?$}{/}; # add slash at end $url .= $entity; - my $e = $self->client->get( $url )->res->json; - warn "# replicated $url ", dump($e); - _chouchdb_put( $self, $database, $entity, $e->{'$id'}, $e ); + my $all = $self->client->get( $url )->res->json; + warn "# replicated $url ", dump($all); + foreach my $e ( @$all ) { + delete $e->{_id}; # sanitize data from older implementation + _couchdb_put( "/$database/$entity." . $e->{'$id'} => $e ); + } } } + _render_jsonp( $self, $got ); } }; -- 2.20.1