Skip to content

refactor(sql): convert SqlQuery and SqlExecute to idiomatic FFI#87

Merged
akonwi merged 1 commit intomainfrom
refactor/sql-ffi-idiomatic
Apr 10, 2026
Merged

refactor(sql): convert SqlQuery and SqlExecute to idiomatic FFI#87
akonwi merged 1 commit intomainfrom
refactor/sql-ffi-idiomatic

Conversation

@akonwi
Copy link
Copy Markdown
Owner

@akonwi akonwi commented Apr 10, 2026

Summary

Converts SqlQuery and SqlExecute from raw FFI to idiomatic FFI, leveraging the recently added []any generator support.

Changes

Before (raw FFI):

func SqlQuery(args []*runtime.Object) *runtime.Object
func SqlExecute(args []*runtime.Object) *runtime.Object

After (idiomatic FFI):

func SqlQuery(conn any, sqlStr string, values []any) ([]any, error)
func SqlExecute(conn any, sqlStr string, values []any) error

Generated Wrappers

func _ffi_SqlQuery(args []*runtime.Object) *runtime.Object {
    arg0 := args[0].Raw()           // conn (any)
    arg1 := args[1].AsString()      // sqlStr
    _sl2 := args[2].AsList()        // values
    arg2 := make([]any, len(_sl2))
    for _i2, _e2 := range _sl2 {
        arg2[_i2] = _e2.Raw()
    }
    result, err := ffi.SqlQuery(arg0, arg1, arg2)
    if err != nil {
        return runtime.MakeErr(runtime.MakeStr(err.Error()))
    }
    _items := make([]*runtime.Object, len(result))
    for _i, _v := range result {
        _items[_i] = runtime.MakeDynamic(_v)
    }
    return runtime.MakeOk(runtime.MakeList(checker.Dynamic, _items...))
}

Cleanup

  • Removed runtime and checker imports from sql.go
  • Removed sqlArgValue helper function (no longer needed)
  • Refactored executeQuery to return ([]any, error)

Stats

  • Raw FFI: 12 → 10
  • Idiomatic FFI: 61 → 63

Testing

  • All unit tests pass
  • SQL module tests pass

- SqlQuery: (conn any, sql string, values []any) ([]any, error)
- SqlExecute: (conn any, sql string, values []any) error
- Remove runtime/checker imports from sql.go
- Remove sqlArgValue helper (no longer needed)
- Refactor executeQuery to return ([]any, error)

Raw FFI count: 12 → 10

Both functions now use []any for values parameter,
which is supported by the generator after recent changes.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ard-lang-dev Ready Ready Preview, Comment Apr 10, 2026 9:51pm

@akonwi akonwi merged commit 293b63b into main Apr 10, 2026
4 checks passed
@akonwi akonwi deleted the refactor/sql-ffi-idiomatic branch April 10, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant