FutureWarningThe
Futuretype was deprecated in SurrealDB 3.0 and is no longer supported. This documentation is provided for reference when working with legacy databases.
The Future class represents uncomputed SurrealQL expressions that are evaluated by the database at query time, rather than at definition time.
Import:
import { Future } from 'surrealdb';
Source: value/future.ts
new Future(body)Create a new future value.
Syntaxnew Future(expression)
| Parameter | Type | Description |
|---|---|---|
body required | string | The SurrealQL expression to evaluate later. |
// Expression evaluated at query time const future = new Future('time::now()'); // Expression with field reference const updated = new Future('$this.updated_at');
.toString()Convert to string representation.
Syntaxfuture.toString()
string - Future notation string
const future = new Future('time::now()'); console.log(future.toString()); // '<future> time::now()'
.toJSON()Serialize for JSON.
Syntaxfuture.toJSON()
string - Future notation
.equals(other)Check if two futures are equal.
Syntaxfuture.equals(other)
boolean - True if equal
NoteThese examples are for reference only. Future is deprecated and should not be used in new applications.
// DEPRECATED: This pattern no longer works in SurrealDB 3.0+ await db.query(` DEFINE FIELD created_at ON TABLE users VALUE ${new Future('time::now()')} DEFAULT ${new Future('time::now()')} `).collect();
// DEPRECATED: Use other mechanisms for auto-updating fields await db.query(` DEFINE FIELD updated_at ON TABLE users VALUE ${new Future('time::now()')} `).collect();
If you’re using Future in your SurrealDB < 3.0 application, here are modern alternatives:
Old (Deprecated):
await db.query(` DEFINE FIELD created_at ON TABLE users DEFAULT ${new Future('time::now()')} `).collect();
New (Recommended):
// Set default in application code await db.create(new Table('users')).content({ name: 'John', created_at: DateTime.now() // Set explicitly }); // Or use database-level defaults await db.query(` DEFINE FIELD created_at ON TABLE users TYPE datetime DEFAULT time::now() `).collect();
Old (Deprecated):
await db.query(` DEFINE FIELD updated_at ON TABLE users VALUE ${new Future('time::now()')} `).collect();
New (Recommended):
// Update in application code await db.update(recordId).merge({ updated_at: DateTime.now() }); // Or use events await db.query(` DEFINE EVENT update_timestamp ON TABLE users WHEN $event = "UPDATE" THEN { UPDATE $after SET updated_at = time::now() } `).collect();
Old (Deprecated):
await db.query(` DEFINE FIELD full_name ON TABLE users VALUE ${new Future('string::concat($this.first_name, " ", $this.last_name)')} `).collect();
New (Recommended):
// Compute in application code const user = await db.select(userId); const fullName = `${user.first_name} ${user.last_name}`; // Or use views await db.query(` DEFINE TABLE user_view AS SELECT *, string::concat(first_name, " ", last_name) AS full_name FROM users `).collect();
The Future type was removed in SurrealDB 3.0 because:
For common use cases previously solved with Future:
| Use Case | Modern Solution |
|---|---|
| Default timestamps | Set in application code or use DEFAULT time::now() |
| Auto-update fields | Use database events or application code |
| Computed fields | Use views or compute in application |
| Field references | Use explicit queries or views |