airtable
Add context to all requests
แพ็คเกจ #Golang อย่างง่ายเพื่อเข้าถึง Airtable API
Golang Airtable API ได้รับการทดสอบเข้ากันได้กับ GO 1.13 ใน UP
go get github.com/mehanizm/airtable
คุณควรได้รับ your_api_token
ในหน้าบัญชี Airtable
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