airtable
Add context to all requests
一个简单的#Golang软件包,可访问可播放的API。
Golang Airtable API已测试与GO 1.13兼容。
go get github.com/mehanizm/airtable
您应该在“ airtable帐户”页面中获得your_api_token
client := airtable . NewClient ( "your_api_token" )
您可以在此处使用自定义HTTP客户端
client . SetCustomClient ( http . DefaultClient )
下面的每种方法都可以与自定义上下文一起使用。只需使用MethodNameContext
调用并提供上下文作为第一个参数。
bases , err := client . GetBases (). WithOffset ( "" ). Do ()
schema , err := client . GetBaseSchema ( "your_database_ID" ). Do ()
要获取your_database_ID
您应该转到主API页面并选择数据库。
table := client . GetTable ( "your_database_ID" , "your_table_name" )
要从桌子上获取记录,您可以使用类似的东西
records , err := table . GetRecords ().
FromView ( "view_1" ).
WithFilterFormula ( "AND({Field1}='value_1',NOT({Field2}='value_2'))" ).
WithSort ( sortQuery1 , sortQuery2 ).
ReturnFields ( "Field1" , "Field2" ).
InStringFormat ( "Europe/Moscow" , "ru" ).
Do ()
if err != nil {
// Handle error
}
recordsToSend := & airtable. Records {
Records : [] * airtable. Record {
{
Fields : map [ string ] any {
"Field1" : "value1" ,
"Field2" : true ,
},
},
},
}
receivedRecords , err := table . AddRecords ( recordsToSend )
if err != nil {
// Handle error
}
record , err := table . GetRecord ( "recordID" )
if err != nil {
// Handle error
}
部分更新一个记录
res , err := record . UpdateRecordPartial ( map [ string ] any { "Field_2" : false })
if err != nil {
// Handle error
}
完整更新记录
toUpdateRecords := & airtable. Records {
Records : [] * airtable. Record {
{
Fields : map [ string ] any {
"Field1" : "value1" ,
"Field2" : true ,
},
},
{
Fields : map [ string ] any {
"Field1" : "value1" ,
"Field2" : true ,
},
},
},
}
updatedRecords , err := table . UpdateRecords ( toUpdateRecords )
if err != nil {
// Handle error
}
res , err := record . DeleteRecord ()
if err != nil {
// Handle error
}
删除多达10个记录
records , err := table . DeleteRecords ([] string { "recordID1" , "recordsID2" })
if err != nil {
// Handle error
}
受到Go Trello API的启发