> ## Documentation Index
> Fetch the complete documentation index at: https://docs.neuro-tech.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Data and persistence

> Query and mutate Neuron objects, external databases, semantic data, and ledger records

The `Waher.Script.Persistence` extension adds SQL-like statements over Neuron's object database. The syntax looks familiar, but sources are .NET types, object collections, vectors, or XML—not relational tables by default.

## Inspect a type

```text theme={null}
Properties(RuntimeCounter)
```

If two loaded assemblies define the same local type name, use the fully qualified .NET type name.

## Select objects

```text theme={null}
SELECT TOP 100
  ObjectId,
  Key,
  GetCounter(Key) AS CurrentValue
FROM RuntimeCounter
WHERE Key LIKE "XMPP.%"
ORDER BY Key
```

Features include projection, aliases, filtering, ordering, grouping, aggregates, implicit groups, wildcards, pagination, and selecting a single object.

Collection names can collide with namespaces. Quote the label to force collection interpretation:

```text theme={null}
SELECT count(*) FROM "RuntimeCounters"
```

## Insert

The engine supports:

```text theme={null}
INSERT INTO CollectionName (Field1,Field2)
VALUES (Value1,Value2)
```

It also supports `INSERT SELECT`, `INSERT OBJECT`, and `INSERT OBJECTS` forms. Prefer inserting typed objects through a package API when invariants or events must be maintained.

## Update and delete

```text theme={null}
UPDATE ExampleType
SET Enabled=false
WHERE ObjectId=TargetId
```

```text theme={null}
DELETE FROM ExampleType
WHERE ObjectId=TargetId
```

<Warning>
  Direct mutation can bypass domain workflows, signatures, notifications, and audit events. Use it for owned operational data, migrations, and recovery procedures—not to alter legal identities, signed contracts, ledger history, or token history.
</Warning>

## Indexes and collections

`CREATE` and `DROP` statements can manage indexes and collections. Run schema operations from a versioned migration with a backup and an idempotent existence check.

## External SQL databases

The `Waher.Script.Data` family can open external connections, execute provider SQL, call stored procedures, and close connections. MySQL and PostgreSQL extensions add provider-specific support. Always parameterize external input and close connections in `finally`.

## Semantic data

With semantic and persistence extensions loaded, Script can execute SPARQL `SELECT`, `ASK`, and `CONSTRUCT` queries. Use the Neuron's SPARQL and graph-store HTTP APIs for cross-process integrations; use Script for local transforms and reports.

## Ledger records

Ledger extensions add `RECORD OBJECT`, `RECORD OBJECTS`, and `REPLAY`. Ledger recording is append-oriented and auditable; it is not a replacement for mutable operational persistence. Record domain events whose history must be provable, then build current projections separately.
