package nosqldb_sdk import ( "C" ) import ( "fmt" "unsafe" "github.com/oracle/nosql-go-sdk/nosqldb" "nosql_db_sdk_ffi/util/ptrproxy" ) //export ffi_nosqldb_client_new func ffi_nosqldb_client_new(unsafe_cfg_ptr NosqldbConfig) (NosqldbClient, Error) { cfg_ptr, ok := ptrproxy.Move(unsafe.Pointer(unsafe_cfg_ptr)) if !ok { return nil, C.CString("NosqldbConfigPtr cannot deref") } cfg := (*nosqldb.Config)(cfg_ptr) // println(*&cfg.Endpoint) // println(*&cfg.Mode) client, err := nosqldb.NewClient(*cfg) if err != nil { return nil, C.CString(err.Error()) } return NosqldbClient(ptrproxy.Ref(unsafe.Pointer(client))), nil } //export ffi_nosqldb_client_close func ffi_nosqldb_client_close(unsafe_nosqldb_client_ptr NosqldbClient) Error { nosqldb_client_ptr, ok := ptrproxy.Move(unsafe.Pointer(unsafe_nosqldb_client_ptr)) if !ok { return C.CString("NosqldbClientPtr cannot deref") } client := (*nosqldb.Client)(nosqldb_client_ptr) err := client.Close() if err != nil { return C.CString(err.Error()) } return nil } //export ffi_nosqldb_client_debug func ffi_nosqldb_client_debug(unsafe_nosqldb_client_ptr NosqldbClient) Error { nosqldb_client_ptr, ok := ptrproxy.Deref(unsafe.Pointer(unsafe_nosqldb_client_ptr)) if !ok { return C.CString("NosqldbClientPtr cannot deref") } client := (*nosqldb.Client)(nosqldb_client_ptr) fmt.Printf("client: %v\n", client) return nil } //export ffi_nosqldb_client_do_table_request func ffi_nosqldb_client_do_table_request(unsafe_nosqldb_client_ptr NosqldbClient, unsafe_nosqldb_treq_ptr NosqldbTableRequest) (NosqldbTableResult, Error) { nosqldb_client_ptr, ok := ptrproxy.Deref(unsafe.Pointer(unsafe_nosqldb_client_ptr)) if !ok { return nil, C.CString("NosqldbClientPtr cannot deref") } client := (*nosqldb.Client)(nosqldb_client_ptr) nosqldb_treq_ptr, ok := ptrproxy.Move(unsafe.Pointer(unsafe_nosqldb_treq_ptr)) if !ok { return nil, C.CString("NosqldbTableRequestPtr cannot deref") } treq := (*nosqldb.TableRequest)(nosqldb_treq_ptr) tres, err := client.DoTableRequest(treq) // test if err != nil { return nil, C.CString(err.Error()) } // tester := NosqldbTableResult(ptrproxy.Ref(unsafe.Pointer(tres))) // tester_nosqldb_client_ptr, tester_ok := ptrproxy.Deref(unsafe.Pointer(tester)) // if !tester_ok { // return nil, C.CString("tester NosqldbClientPtr cannot deref") // } // tester_client := (*nosqldb.TableRequest)(tester_nosqldb_client_ptr) // fmt.Printf("tres: %v\n", tres) // fmt.Printf("tester: %v\n", tester) // fmt.Printf("tester_nosqldb_client_ptr: %v\n", tester_nosqldb_client_ptr) // if tester_client == nil { // fmt.Printf("tester_client: nil\n") // } else { // fmt.Printf("tester_client: %v\n", tester_client) // } // return tester, nil return NosqldbTableResult(ptrproxy.Ref(unsafe.Pointer(tres))), nil } //export ffi_nosqldb_client_Put func ffi_nosqldb_client_Put(unsafe_nosqldb_client_ptr NosqldbClient, unsafe_nosqldb_ptrq_ptr NosqldbPutRequest) (NosqldbPutResult, Error) { nosqldb_client_ptr, ok := ptrproxy.Deref(unsafe.Pointer(unsafe_nosqldb_client_ptr)) if !ok { return nil, C.CString("NosqldbClientPtr cannot deref") } client := (*nosqldb.Client)(nosqldb_client_ptr) nosqldb_ptrq_ptr, ok := ptrproxy.Move(unsafe.Pointer(unsafe_nosqldb_ptrq_ptr)) if !ok { return nil, C.CString("NosqldbPutrequestPtr cannot deref") } ptrq := (*nosqldb.PutRequest)(nosqldb_ptrq_ptr) ptrs, err := client.Put(ptrq) if err != nil { return nil, C.CString(err.Error()) } return NosqldbPutResult(ptrproxy.Ref(unsafe.Pointer(ptrs))), nil } //export ffi_nosqldb_client_Get func ffi_nosqldb_client_Get(unsafe_nosqldb_client_ptr NosqldbClient, unsafe_nosqldb_gtrq_ptr NosqldbGetRequest) (NosqldbGetResult, Error) { nosqldb_client_ptr, ok := ptrproxy.Deref(unsafe.Pointer(unsafe_nosqldb_client_ptr)) if !ok { return nil, C.CString("NosqldbClientPtr cannot deref") } client := (*nosqldb.Client)(nosqldb_client_ptr) nosqldb_gtrq_ptr, ok := ptrproxy.Move(unsafe.Pointer(unsafe_nosqldb_gtrq_ptr)) if !ok { return nil, C.CString("NosqldbGetrequestPtr cannot deref") } gtrq := (*nosqldb.GetRequest)(nosqldb_gtrq_ptr) gtrs, err := client.Get(gtrq) if err != nil { return nil, C.CString(err.Error()) } return NosqldbGetResult(ptrproxy.Ref(unsafe.Pointer(gtrs))), nil } //export ffi_nosqldb_client_Delete func ffi_nosqldb_client_Delete(unsafe_nosqldb_client_ptr NosqldbClient, unsafe_nosqldb_dltrq_ptr NosqldbDeleteRequest) (NosqldbDeleteResult, Error) { nosqldb_client_ptr, ok := ptrproxy.Deref(unsafe.Pointer(unsafe_nosqldb_client_ptr)) if !ok { return nil, C.CString("NosqldbClientPtr cannot deref") } client := (*nosqldb.Client)(nosqldb_client_ptr) nosqldb_dltrq_ptr, ok := ptrproxy.Move(unsafe.Pointer(unsafe_nosqldb_dltrq_ptr)) if !ok { return nil, C.CString("NosqldbDeleterequestPtr cannot deref") } dltrq := (*nosqldb.DeleteRequest)(nosqldb_dltrq_ptr) dltrs, err := client.Delete(dltrq) if err != nil { return nil, C.CString(err.Error()) } return NosqldbDeleteResult(ptrproxy.Ref(unsafe.Pointer(dltrs))), nil } //export ffi_nosqldb_client_prepare func ffi_nosqldb_client_prepare(unsafe_nosqldb_client_ptr NosqldbClient, unsafe_nosqldb_preprq_ptr NosqldbPrepareRequest) (NosqldbPrepareResult, Error) { nosqldb_client_ptr, ok := ptrproxy.Deref(unsafe.Pointer(unsafe_nosqldb_client_ptr)) if !ok { return nil, C.CString("NosqldbClientPtr cannot deref") } client := (*nosqldb.Client)(nosqldb_client_ptr) nosqldb_preprq_ptr, ok := ptrproxy.Move(unsafe.Pointer(unsafe_nosqldb_preprq_ptr)) if !ok { return nil, C.CString("NosqldbPrepareRequestPtr cannot deref") } preprq := (*nosqldb.PrepareRequest)(nosqldb_preprq_ptr) preprs, err := client.Prepare(preprq) if err != nil { return nil, C.CString(err.Error()) } return NosqldbPrepareResult(ptrproxy.Ref(unsafe.Pointer(preprs))), nil } //export ffi_nosqldb_client_query func ffi_nosqldb_client_query(unsafe_nosqldb_client_ptr NosqldbClient, unsafe_nosqldb_queryrq_ptr NosqldbQueryRequest) (NosqldbQueryResult, Error) { nosqldb_client_ptr, ok := ptrproxy.Deref(unsafe.Pointer(unsafe_nosqldb_client_ptr)) if !ok { return nil, C.CString("NosqldbClientPtr cannot deref") } client := (*nosqldb.Client)(nosqldb_client_ptr) nosqldb_queryrq_ptr, ok := ptrproxy.Deref(unsafe.Pointer(unsafe_nosqldb_queryrq_ptr)) if !ok { return nil, C.CString("NosqldbQueryRequestPtr cannot deref") } queryrq := (*nosqldb.QueryRequest)(nosqldb_queryrq_ptr) queryrs, err := client.Query(queryrq) if err != nil { return nil, C.CString(err.Error()) } return NosqldbQueryResult(ptrproxy.Ref(unsafe.Pointer(queryrs))), nil }