Cerial
Field Types

Email

Email field type in Cerial — stored as a string with SurrealDB-enforced email format validation.

The Email field type stores an email address as a string, but with a key difference: SurrealDB enforces valid email format through a string::is::email assertion on the field. Attempting to insert or update a record with an invalid email will cause a validation error at the database level.

Schema Syntax

model User {
  id Record @id
  email Email @unique
  backupEmail Email?
  defaultContact Email @default("admin@example.com")
}

Types

DirectionType
Outputstring
Inputstring
SurrealDBstring (with string::is::email assertion)

At the TypeScript level, Email behaves identically to String. The validation happens in SurrealDB, not at compile time.

Create & Update

const user = await client.db.User.create({
  data: {
    email: 'alice@example.com',
    backupEmail: 'alice.backup@example.com',
  },
});

console.log(user.email);  // 'alice@example.com'

// Update
await client.db.User.updateUnique({
  where: { id: user.id },
  data: { email: 'alice.new@example.com' },
});

// This would fail at the database level — invalid email format:
// data: { email: 'not-an-email' }

Filtering

Email fields support the same operators as strings:

// Exact match
const alice = await client.db.User.findMany({
  where: { email: { eq: 'alice@example.com' } },
});

// Domain search
const gmailUsers = await client.db.User.findMany({
  where: { email: { endsWith: '@gmail.com' } },
});

// Set
const specific = await client.db.User.findMany({
  where: { email: { in: ['alice@example.com', 'bob@example.com'] } },
});

Available Operators

OperatorDescription
eqEqual to
neqNot equal to
inIn a set of values
notInNot in a set of values
containsContains substring
startsWithStarts with prefix
endsWithEnds with suffix

Conditional Operators

OperatorAvailable whenDescription
not? or @nullableNegated comparison
isNone? (optional)true = field is absent
isNull@nullabletrue = field is null
isDefinedAlwaystrue = field exists

OrderBy

Email fields support orderBy:

const sorted = await client.db.User.findMany({
  orderBy: { email: 'asc' },
});

In Objects and Tuples

object ContactInfo {
  primary Email
  secondary Email?
}

tuple EmailPair {
  work Email,
  personal Email
}

model Employee {
  id Record @id
  contact ContactInfo
  emails EmailPair
}
const emp = await client.db.Employee.create({
  data: {
    contact: { primary: 'work@company.com' },
    emails: ['work@company.com', 'me@home.com'],
  },
});

emp.contact.primary;  // 'work@company.com'
emp.emails[1];        // 'me@home.com'

Arrays

model Newsletter {
  id Record @id
  recipients Email[]
  uniqueRecipients Email[] @set
}

Email arrays support @set for auto-deduplicated, sorted arrays. They also support @distinct and @sort decorators.

Supported Decorators

DecoratorEffect
@default(value)Default value on create
@defaultAlways(value)Reset to value on every write
@nullableAllow explicit null
@readonlyWrite-once field
@indexDatabase index
@uniqueUnique constraint

On this page