SurrealDB
SurrealDB Docs Logo

Enter a search query

Navigation

Future

Warning

The Future type 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

Constructor

new Future(body)

Create a new future value.

Syntax
new Future(expression)

Parameters

ParameterTypeDescription
body requiredstringThe SurrealQL expression to evaluate later.

Example

// Expression evaluated at query time const future = new Future('time::now()'); // Expression with field reference const updated = new Future('$this.updated_at');

Instance Methods

.toString()

Convert to string representation.

Syntax
future.toString()

Returns

string - Future notation string

Example

const future = new Future('time::now()'); console.log(future.toString()); // '<future> time::now()'

.toJSON()

Serialize for JSON.

Syntax
future.toJSON()

Returns

string - Future notation


.equals(other)

Check if two futures are equal.

Syntax
future.equals(other)

Returns

boolean - True if equal

Legacy Examples

Note

These examples are for reference only. Future is deprecated and should not be used in new applications.

Schema Default Values (Legacy)

// 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();

Auto-Update Timestamps (Legacy)

// DEPRECATED: Use other mechanisms for auto-updating fields await db.query(` DEFINE FIELD updated_at ON TABLE users VALUE ${new Future('time::now()')} `).collect();

Migration Guide

If you’re using Future in your SurrealDB < 3.0 application, here are modern alternatives:

Default Timestamps

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();

Auto-Update Fields

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();

Field References

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();

Why Was Future Deprecated?

The Future type was removed in SurrealDB 3.0 because:

  1. Complexity - Added unnecessary complexity to the query engine
  2. Performance - Could cause unexpected performance issues
  3. Predictability - Made query behavior less predictable
  4. Alternatives - Better alternatives exist (events, views, application-side logic)

Alternatives

For common use cases previously solved with Future:

Use CaseModern Solution
Default timestampsSet in application code or use DEFAULT time::now()
Auto-update fieldsUse database events or application code
Computed fieldsUse views or compute in application
Field referencesUse explicit queries or views

See Also