Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

NocoDB Golang SDK

License

NotificationsYou must be signed in to change notification settings

eduardolat/nocodbgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go ReferenceGo Report CardRelease VersionLicense

A Zero-Dependency Go client for theNocoDB API.This client provides a simple and intuitive way to interact with the NocoDB APIusing a fluent chain pattern.

Warning

This client is not yet stable and the API signature may change in the futureuntil it reaches version 1.0.0, so be careful when upgrading. However, the APIsignature should not change too much.

Installation

Go version 1.22 or higher is required.

go get github.com/eduardolat/nocodbgo

Usage

Most modern code editors will provide autocompletion to guide you through theavailable options as you type. This makes using the SDK intuitive and easy tolearn.

You can find examples of how to use the client in theexamplesdirectory.

You can also hover over the methods provided by the client to read more aboutthem.

Creating a client

package mainimport ("github.com/eduardolat/nocodbgo")funcmain() {// Create a new client using the chain patternclient,err:=nocodbgo.NewClient().WithBaseURL("https://example.com").WithAPIToken("your-api-token").Create()iferr!=nil {// Handle error}}

Basic CRUD Operations

// Get a tabletable:=client.Table("your-table-id")// Create a record (can be a map[string]any or a struct with JSON tags)user:=map[string]any{"Name":"John Doe","Email":"john@example.com","Age":30,}// Create a recorduserID,err:=table.CreateRecord(user).Execute()// Read a recordreadResponse,err:=table.ReadRecord(userID).// Optional, if not provided a context.Background() will be usedWithContext(context.Background()).ReturnFields("Name","Email","Age").Execute()// Decode into a structtypeUserstruct {IDint`json:"Id"`Namestring`json:"Name"`Emailstring`json:"Email"`Ageint`json:"Age"`}varuserStructUsererr=readResponse.DecodeInto(&userStruct)// Update a recordupdateUser:=map[string]any{"Id":userID,// ID must be included"Name":"John Smith",}err=table.UpdateRecord(updateUser).Execute()// Delete a recorderr=table.DeleteRecord(userID).Execute()

Listing and Filtering Records

// List records with options using the chain patternresult,err:=table.ListRecords().Where("(Age,gt,18)").SortAscBy("Name").Limit(10).Execute()// Decode the list into a structvarusers []Usererr=result.DecodeInto(&users)// Count recordscount,err:=table.CountRecords().Where("(Age,gt,18)").Execute()

Complex Filters

// Query with complex filters using specific methodsresult,err:=table.ListRecords().WhereIsEqualTo("Name","John Smith").WhereIsGreaterThan("Age","18").WhereIsLessThan("Age","30").SortAscBy("Name").Limit(10).Execute()// Query with custom filtersresult,err:=table.ListRecords().Where("(Age,gt,20)~or(Email,like,%@example.com)").SortDescBy("Age").Limit(5).Execute()

Operations with Multiple Records

// Create multiple recordsusers:= []map[string]any{    {"Name":"Jane Doe","Email":"jane@example.com","Age":25,    },    {"Name":"Bob Smith","Email":"bob@example.com","Age":40,    },}createdIDs,err:=table.CreateRecords(users).Execute()// Update multiple recordsupdateUsers:= []map[string]any{    {"Id":createdIDs[0],"Name":"Jane Smith",    },    {"Id":createdIDs[1],"Name":"Robert Smith",    },}err=table.UpdateRecords(updateUsers).Execute()// Delete multiple recordserr=table.DeleteRecords(createdIDs).Execute()

Working with Linked Records

// List linked recordslinkedRecords,err:=table.ListLinks("link-field-id",recordID).ReturnFields("Name","Email").SortAscBy("Name").Limit(10).Where("(Age,gt,18)").Execute()// Decode the linked recordsvarlinkedUsers []Usererr=linkedRecords.DecodeInto(&linkedUsers)// Create a linkerr=table.CreateLink("link-field-id",recordID,targetID).Execute()// Create multiple linkserr=table.CreateLinks("link-field-id",recordID, []int{1,2,3}).Execute()// Delete a linkerr=table.DeleteLink("link-field-id",recordID,targetID).Execute()// Delete multiple linkserr=table.DeleteLinks("link-field-id",recordID, []int{1,2}).Execute()

Additional Options

// Use a specific viewresult,err:=table.ListRecords().WithViewId("view-id").Execute()// Shuffle results randomlyresult,err:=table.ListRecords().Shuffle().Limit(5).Execute()// Paginationresult,err:=table.ListRecords().Page(2,10).// Page 2, 10 records per pageExecute()

Context Control

All operations support the use ofcontext.Context for cancellation and timeoutcontrol:

ctx,cancel:=context.WithTimeout(context.Background(),5*time.Second)defercancel()result,err:=table.ListRecords().WithContext(ctx).Where("(Age,gt,18)").Execute()

If you don't provide a context, a context.Background() will be used.

License

This project is licensed under the MIT License - see theLICENSE filefor details.


[8]ページ先頭

©2009-2025 Movatter.jp