PHPackages                             prewk/snapper-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. prewk/snapper-php

ActiveLibrary

prewk/snapper-php
=================

Anonymized (de)serialization

3.2.6(8y ago)034MITPHPPHP &gt;=7

Since Dec 1Pushed 7y ago1 watchersCompare

[ Source](https://github.com/prewk/snapper-php)[ Packagist](https://packagist.org/packages/prewk/snapper-php)[ Docs](http://github.com/prewk/snapper-php)[ RSS](/packages/prewk-snapper-php/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (11)Versions (35)Used By (0)

Snapper 🐡 [![Coverage Status](https://camo.githubusercontent.com/d8291c603ae89e8d372cfb6146068695234bee156f7b15ab9f79153667e77f85/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f707265776b2f736e61707065722d7068702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/prewk/snapper-php?branch=master) [![Build Status](https://camo.githubusercontent.com/15bb796e9ba52c680190a4c11454164eedc68d376292a5c38ed9304fb30000bb/68747470733a2f2f7472617669732d63692e6f72672f707265776b2f736e61707065722d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/prewk/snapper-php)
==========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#snapper---)

Converts rows from a relational database into serialization snapshots that can be deserialized into new rows at a later time with complex relationships preserved.

Example
-------

[](#example)

### From database into the serializer

[](#from-database-into-the-serializer)

```
// Parent table "parents"
[
  "id" => 1,
  "name" => "The parent",
  "favorite_child" => 2 // Note: Circular dependency
],
// Child table "children"
[
  "id" => 1,
  "parent_id" => 1,
  "description" => "I'm child A"
],
// Child table "children"
[
  "id" => 2,
  "parent_id" => 1, // Note: Circular dependency
  "description" => "I'm child B"
]

```

### Out from the serializer

[](#out-from-the-serializer)

```
[
  "op" => "INSERT",
  "type" => "parents",
  "rows" => [
    [
      "id" => "dee78c67-7c0b-4750-9f44-414f5a45006f",
      "name" => "The parent",
      "favorite_child" => null
    ]
  ]
],
[
  "op" => "INSERT",
  "type" => "children",
  "rows" => [
    [
      "id" => "3d228dca-11e2-43ec-bb03-ea4dace489f7",
      "parent_id" => "dee78c67-7c0b-4750-9f44-414f5a45006f",
      "description" => "I'm child A"
    ],
    [
      "id" => "9eebf63a-69a5-42c7-b1fb-81a5e2058ec9",
      "parent_id" => "dee78c67-7c0b-4750-9f44-414f5a45006f",
      "description" => "I'm child B"
    ]
  ]
],
[
  "op" => "UPDATE",
  "type" => "parents",
  "rows" => [
    [
      "id" => "dee78c67-7c0b-4750-9f44-414f5a45006f",
      "favorite_child" => "9eebf63a-69a5-42c7-b1fb-81a5e2058ec9"
    ]
  ]
]

```

### Deserialize into database again

[](#deserialize-into-database-again)

```
INSERT INTO parents (name, favorite_child) VALUES ("The parent", NULL); (LAST_INSERT_ID 555)
INSERT INTO children (parent_id, description) VALUES (555, "I'm child A"); (LAST_INSERT_ID 333)
INSERT INTO children (parent_id, description) VALUES (555, "I'm child B"); (LAST_INSERT_ID 334)
UPDATE parents SET favorite_child = 334 WHERE id = 555;

```

### How to serialize?

[](#how-to-serialize)

```
