Skip to content

Conversation

@Bullrich
Copy link

@Bullrich Bullrich commented Nov 1, 2025

What does this PR do?

Adds Go language support to the Appwrite CLI types generation feature.

Test Plan

  • Generated Go types successfully using appwrite types --language go types
  • Verified output generates proper Go structs with JSON tags
Example of files created with the feature

I ran appwrite types --language go with the following file:

    "tables": [
        {
            "$id": "function-runs",
            "$permissions": [],
            "databaseId": "workflow-engine",
            "name": "Function Runs",
            "enabled": true,
            "rowSecurity": false,
            "columns": [
                {
                    "key": "function_status",
                    "type": "string",
                    "required": false,
                    "array": false,
                    "elements": [
                        "pending",
                        "running",
                        "failed",
                        "complete"
                    ],
                    "format": "enum",
                    "default": null
                },
                {
                    "key": "execution_id",
                    "type": "string",
                    "required": false,
                    "array": false,
                    "size": 256,
                    "default": null,
                    "encrypt": false
                },
                {
                    "key": "function",
                    "type": "string",
                    "required": true,
                    "array": false,
                    "size": 128,
                    "default": null,
                    "encrypt": false
                },
                {
                    "key": "payload",
                    "type": "string",
                    "required": true,
                    "array": false,
                    "size": 65535,
                    "default": null,
                    "encrypt": false
                },
                {
                    "key": "output",
                    "type": "string",
                    "required": false,
                    "array": false,
                    "size": 512,
                    "default": "Not executed yet",
                    "encrypt": false
                }
            ],
            "indexes": []
        },
        {
            "$id": "idempotency",
            "$permissions": [],
            "databaseId": "workflow-engine",
            "name": "Idempotency",
            "enabled": true,
            "rowSecurity": false,
            "columns": [
                {
                    "key": "idempotency_status",
                    "type": "string",
                    "required": true,
                    "array": false,
                    "elements": [
                        "processing",
                        "succeeded",
                        "failed",
                        "pending"
                    ],
                    "format": "enum",
                    "default": null
                },
                {
                    "key": "result_ref",
                    "type": "string",
                    "required": false,
                    "array": false,
                    "size": 1024,
                    "default": null,
                    "encrypt": false
                },
                {
                    "key": "error_code",
                    "type": "string",
                    "required": false,
                    "array": false,
                    "size": 256,
                    "default": null,
                    "encrypt": false
                },
                {
                    "key": "function_run",
                    "type": "relationship",
                    "required": false,
                    "array": false,
                    "relatedTable": "function-runs",
                    "relationType": "manyToOne",
                    "twoWay": false,
                    "twoWayKey": "6906546e00118271ccd3",
                    "onDelete": "cascade",
                    "side": "parent"
                }
            ],
            "indexes": []
        }
    ]

And got the following files:
types/function_runs.go

package models

/**
 * This file is auto-generated by the Appwrite CLI. 
 * You can regenerate it by running `appwrite types --language go types`.
 */

type FunctionStatus string

const (
	FunctionStatusPending FunctionStatus = "pending"
	FunctionStatusRunning FunctionStatus = "running"
	FunctionStatusFailed FunctionStatus = "failed"
	FunctionStatusComplete FunctionStatus = "complete"
)

type FunctionRuns struct {
	FunctionStatus *FunctionStatus `json:"function_status"`
	ExecutionId *string `json:"execution_id"`
	Function string `json:"function"`
	Payload string `json:"payload"`
	Output string `json:"output"`
}

types/idempotency.go

package models

/**
 * This file is auto-generated by the Appwrite CLI. 
 * You can regenerate it by running `appwrite types --language go types`.
 */

type IdempotencyStatus string

const (
	IdempotencyStatusProcessing IdempotencyStatus = "processing"
	IdempotencyStatusSucceeded IdempotencyStatus = "succeeded"
	IdempotencyStatusFailed IdempotencyStatus = "failed"
	IdempotencyStatusPending IdempotencyStatus = "pending"
)

type Idempotency struct {
	IdempotencyStatus IdempotencyStatus `json:"idempotency_status"`
	ResultRef *string `json:"result_ref"`
	ErrorCode *string `json:"error_code"`
	FunctionRun FunctionRuns `json:"function_run"`
}

Related Issues

Fixes appwrite/.github#127

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

  • My code follows the style guidelines of this project
  • I have tested my changes
  • The changes generate valid Go code

Summary by CodeRabbit

  • New Features
    • Added Go language support for automatic type code generation.
    • Automatic Go project detection enabled.
    • Full type mapping support including primitives, enums, relationships, arrays, and optional types.
    • Generated Go files include proper struct definitions with JSON tag formatting.

## What does this PR do?
Adds Go language support to the Appwrite CLI types generation feature.

## Test Plan
- Generated Go types successfully using `appwrite types --language go types`
- Verified output generates proper Go structs with JSON tags
- Tested enum generation
- Tested optional fields (pointer types)
- Tested array types (slice syntax)

## Related Issues
Fixes appwrite/.github#127

## Type of change
- [x] New feature (non-breaking change which adds functionality)

## Checklist
- [x] My code follows the style guidelines of this project
- [x] I have tested my changes
- [x] The changes generate valid Go code
@coderabbitai
Copy link

coderabbitai bot commented Nov 1, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This change adds Go programming language support to the type generation system. It introduces a new Go language module that generates Go structs and enums from collection definitions, integrates Go detection into the language detection logic by checking for go.mod and go.sum files, and registers Go as an available language choice in the command handler.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Type mapping implementation (lib/type-generation/languages/go.js): Verify correctness of attribute-to-Go-type mappings, including handling of relationships (one-to-many, many-to-one, many-to-many), optional pointer types, and error cases for unknown types or missing collections
  • Template generation logic: Ensure the Go struct and enum code generation produces valid Go syntax, particularly JSON tag formatting and const block generation for enums
  • Go project detection (lib/type-generation/languages/language.js): Confirm that go.mod and go.sum file detection correctly identifies Go projects
  • Integration points (lib/commands/types.js): Verify the case handler for "go" and inclusion in language choices follow the established pattern for other languages
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 44c7c7d and 14c7cda.

📒 Files selected for processing (3)
  • lib/commands/types.js (3 hunks)
  • lib/type-generation/languages/go.js (1 hunks)
  • lib/type-generation/languages/language.js (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Nov 1, 2025

This library is auto-generated by the Appwrite SDK Generator, and does not accept pull requests directly. To learn more about how you can help us improve this SDK, please check the contributing guide.

@github-actions github-actions bot closed this Nov 1, 2025
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.

Support Go lang type generation from the database schema

1 participant