77 "strings"
88 "time"
99
10- "github.com/appwrite/sdk-for-go/v2 /appwrite"
11- "github.com/appwrite/sdk-for-go/v2 /client"
10+ "github.com/appwrite/sdk-for-go/v3 /appwrite"
11+ "github.com/appwrite/sdk-for-go/v3 /client"
1212 "github.com/hashicorp/terraform-plugin-framework/path"
1313 "github.com/hashicorp/terraform-plugin-framework/resource"
1414 "github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -79,34 +79,27 @@ func FormatError(err error) string {
7979 return err .Error ()
8080}
8181
82- // DecodeColumn decodes the raw *interface{} response from GetColumn into a typed model.
83- func DecodeColumn (raw * interface {}, target interface {}) error {
84- if raw == nil {
85- return fmt .Errorf ("nil response from GetColumn" )
86- }
87- switch v := (* raw ).(type ) {
88- case string :
89- return json .Unmarshal ([]byte (v ), target )
90- default :
91- b , err := json .Marshal (v )
92- if err != nil {
93- return fmt .Errorf ("failed to marshal GetColumn response: %w" , err )
94- }
95- return json .Unmarshal (b , target )
96- }
97- }
98-
99- // GetColumnStatus extracts the status field from a raw GetColumn response.
100- func GetColumnStatus (raw * interface {}) (string , error ) {
101- if raw == nil {
102- return "" , fmt .Errorf ("nil response" )
103- }
104- var generic map [string ]interface {}
105- if err := DecodeColumn (raw , & generic ); err != nil {
106- return "" , err
107- }
108- status , _ := generic ["status" ].(string )
109- return status , nil
82+ // GetColumnRaw fetches a column using a raw API call, bypassing the SDK's
83+ // type-matching logic which doesn't handle all column types (e.g. text,
84+ // longtext, mediumtext, varchar, point, line, polygon).
85+ func GetColumnRaw (c client.Client , databaseID , tableID , key string ) (map [string ]interface {}, error ) {
86+ path := fmt .Sprintf ("/tablesdb/%s/tables/%s/columns/%s" , databaseID , tableID , key )
87+ resp , err := c .Call ("GET" , path , map [string ]interface {}{}, map [string ]interface {}{
88+ "databaseId" : databaseID ,
89+ "tableId" : tableID ,
90+ "key" : key ,
91+ })
92+ if err != nil {
93+ return nil , err
94+ }
95+ if ! strings .HasPrefix (resp .Type , "application/json" ) {
96+ return nil , fmt .Errorf ("unexpected response type: %s" , resp .Type )
97+ }
98+ var result map [string ]interface {}
99+ if err := json .Unmarshal ([]byte (resp .Result .(string )), & result ); err != nil {
100+ return nil , fmt .Errorf ("failed to unmarshal column response: %w" , err )
101+ }
102+ return result , nil
110103}
111104
112105// AttrCheck holds the result of an attribute mismatch check.
@@ -200,7 +193,7 @@ func WaitForDeploymentReady(ctx context.Context, getDeployment func() (string, e
200193
201194// WaitForColumnAvailable polls a column until its status becomes "available",
202195// with a maximum wait of 60 seconds.
203- func WaitForColumnAvailable (ctx context.Context , getColumn func () (* interface {}, error ), key string ) error {
196+ func WaitForColumnAvailable (ctx context.Context , getColumn func () (interface {}, error ), key string ) error {
204197 deadline := time .After (60 * time .Second )
205198 for {
206199 select {
@@ -216,7 +209,10 @@ func WaitForColumnAvailable(ctx context.Context, getColumn func() (*interface{},
216209 return fmt .Errorf ("error checking column %q status: %w" , key , err )
217210 }
218211
219- status , _ := GetColumnStatus (raw )
212+ var status string
213+ if m , ok := raw .(map [string ]interface {}); ok {
214+ status , _ = m ["status" ].(string )
215+ }
220216 switch status {
221217 case "available" :
222218 return nil
0 commit comments