Stately’s API offers a small handful of simple methods for creating and accessing your Items.
Prerequisites
Create a Stately account and a Store
Install an SDK for your language
Define a schema and generate language-specific code
Set up a client to talk to your Store
Saving Items with Put
Using the simple User item type from Define a Schema , we can quickly create new Users and Put them into our Store:
" github.com/StatelyCloud/go-sdk/stately "
// This is the code you generated from schema
" github.com/StatelyCloud/stately/go-sdk-sample/schema "
user , err := client . Put ( ctx , & schema.User{
// No Id is needed, it will be auto-generated by Stately
DisplayName : " Stately Support " ,
LastLoginDate : time . Now (). Unix (),
userID := user .( * schema.User). Id
item = client.put( StatelyDB :: Types :: User . new (
# No id is needed, it will be auto-generated by Stately
displayName: " Stately Support " ,
lastLoginDate: Time ::now.to_i,
from __future__ import annotations
from typing import TYPE_CHECKING
from statelydb import Client, key_path
async def create_user ( client : Client ) -> None :
# No id is needed, it will be auto-generated by Stately
displayName = " Stately Support " ,
lastLoginDate = time. time () ,
import { keyPath } from " @stately-cloud/client " ;
} from " ./schema/index.js " ;
async function createUser ( client : DatabaseClient ) {
const item = await client . put (
// No id is needed, it will be auto-generated by Stately
displayName: " Stately Support " ,
lastLoginDate: BigInt (Date . now () / 1000 ) ,
Our generated code contains typed objects for the User item type, so we can directly create that object and then call client.put
to save it. The returned value is the version of the item that was saved in the database, including fields that StatelyDB filled in, such as the User’s new id
.
Retrieving Items with Get
We can Get the user back using its key path:
" github.com/StatelyCloud/go-sdk/stately "
// This is the code you generated from schema
" github.com/StatelyCloud/stately/go-sdk-sample/schema "
) ( * schema.User, error ) {
" /usr- " + stately . ToKeyID ( userID ),
return item .( * schema.User), nil
def get_user ( client , user_id )
user = client.get( StatelyDB :: KeyPath .with( ' usr ' , user_id))
from __future__ import annotations
from typing import TYPE_CHECKING
from statelydb import Client, key_path
async def get_user ( client : Client, user_id : UUID ) -> User | None :
return await client. get ( User , key_path ( " /usr- {id} " , id = user_id ))
import { keyPath } from " @stately-cloud/client " ;
} from " ./schema/index.js " ;
) : Promise < User | undefined > {
const user = await client . get ( " User " , keyPath ` /usr- ${ userID } ` );
More APIs
Put
and Get
are the two most basic APIs - see Basic Data APIs , List , and Transactions for more things you can do.