Storing Info in a Database

The Fuel indexer uses PostgreSQL as the primary database.

💡 We're open to supporting other storage solutions in the future.

Data Types

Below is a mapping of GraphQL schema types to their Sway and database equivalents. Note that an empty cell denotes that there is no direct equivalent for the type in the corresponding domain.

GraphQL ScalarSway TypePostgres Type
Addressb256varchar(64)
AssetIdu8[32]varchar(64)
Booleanboolboolean
Bytesstr[]varchar(10485760)
Bytes32str[32]varchar(64)
Bytes4str[4]varchar(8)
Bytes64str[64]varchar(128)
Bytes8str[8]varchar(16)
ContractIdb256varchar(64)
I128numeric(39,0)
I32u32integer
I64u64bigint
I8u8integer
IDvarchar(64) primary key
Jsonstr[]json
U128numeric(39, 0)
U32u32integer
U64u64numeric(20, 0)
U8u8integer
UIDvarchar(64)
Stringstr[]varchar(255)

Example

Let's define an Event struct in a Sway contract:

struct Event {
    id: u64,
    address: Address,
    block_height: u64,
}

The corresponding GraphQL schema to mirror this Event struct would resemble:

type Event @entity {
    id: ID!
    account: Address!
    block_height: U64!
}

And finally, this GraphQL schema will generate the following Postgres schema:

                                           Table "schema.event"
    Column   |     Type    | Collation | Nullable | Default | Storage  | Compression | Stats target | Description
--------------+-------------+-----------+----------+---------+----------+-------------+--------------+-------------
 id           |    bigint   |           | not null |         | plain    |             |              |
 block_height |    bigint   |           | not null |         | plain    |             |              |
 address      | varchar(64) |           | not null |         | plain    |             |              |
 object       |    bytea    |           | not null |         | extended |             |              |
Indexes:
    "event_pkey" PRIMARY KEY, btree (id)
Access method: heap