Skip to content

fix(database/gdb): Fix GetArray return type and add Bools method#4452

Merged
hailaz merged 3 commits intomasterfrom
enhance/gdb-array
Sep 28, 2025
Merged

fix(database/gdb): Fix GetArray return type and add Bools method#4452
hailaz merged 3 commits intomasterfrom
enhance/gdb-array

Conversation

@hailaz
Copy link
Contributor

@hailaz hailaz commented Sep 28, 2025

Change the return type of the GetArray method to Array for consistency in data structure. Introduce a new Bools method to convert Vars to a slice of bools, along with corresponding test cases to validate the functionality.

// 改进前
res, _ := db.Model(table).Fields("id").Array()
ids := make([]int64, 0, len(res))
for _, v := range res {
ids = append(ids, v.Int64())
}
g.Dump(ids)
// 改进后
res, _ := db.Model(table).Fields("id").Array()
ids := res.Int64s()
g.Dump(ids)

@hailaz hailaz requested review from Copilot and houseme September 28, 2025 02:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the return type inconsistency in the GetArray method throughout the database package and adds a new Bools method to the gvar.Vars type for converting variables to boolean slice.

  • Changed GetArray method return type from []Value to Array across database interfaces and implementations
  • Added Bools method to gvar.Vars for converting variables to []bool
  • Improved memory allocation efficiency in existing conversion methods by pre-allocating slices with capacity

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
frame/gins/gins_database.go Updated database configuration method calls to use GetConfigGroup
database/gdb/gdb_type_result.go Changed Array method return type from []Value to Array
database/gdb/gdb_model_select.go Updated Model.Array return type from []Value to Array
database/gdb/gdb_core.go Changed Core.GetArray return type from []Value to Array
database/gdb/gdb.go Updated DB interface GetArray signature and added Array type alias
container/gvar/gvar_z_unit_vars_test.go Added comprehensive test cases for new Bools method
container/gvar/gvar_vars.go Added Bools method and optimized slice allocation in conversion methods

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@hailaz hailaz merged commit f565a34 into master Sep 28, 2025
36 of 38 checks passed
@hailaz hailaz deleted the enhance/gdb-array branch September 28, 2025 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants