Skip to content

State Persistence

Aryeh Citron edited this page Apr 28, 2026 · 2 revisions

State Persistence

Export/Import

Save and restore table state as JSON for reproducible test fixtures.

Export

using var bq = InMemoryBigQuery.Create("test-project", "my_dataset", ds =>
{
    ds.AddTable("users", schema);
});

// Insert some data
await bq.Client.InsertRowsAsync("my_dataset", "users", testRows);

// Export state to JSON
string json = bq.Store.ExportState();
File.WriteAllText("test-fixture.json", json);

Import

using var bq = InMemoryBigQuery.Create("test-project");

// Import state from JSON
string json = File.ReadAllText("test-fixture.json");
bq.Store.ImportState(json);

// All datasets, tables, and rows are restored
var results = await bq.Client.ExecuteQueryAsync(
    "SELECT * FROM my_dataset.users", null);

Export to File / Import from File

Convenience methods that handle file I/O:

// Export directly to a file
bq.Store.ExportStateToFile("test-fixture.json");

// Import directly from a file
bq.Store.ImportStateFromFile("test-fixture.json");

Clone this wiki locally