{"modulePath":"github.com/Compogo/db-sql-generator","version":"v0.0.4","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package db_sql_generator\n\n## Variables\n\n```go\nvar Component = \u0026component.Component{\n\tInit: component.StepFunc(func(container container.Container) error {\n\t\treturn container.Provides(\n\t\t\tNewConfig,\n\t\t\tNewGenerator,\n\t\t)\n\t}),\n\tConfiguration: component.StepFunc(func(container container.Container) error {\n\t\treturn container.Invoke(Configuration)\n\t}),\n}\n```\nComponent is a ready-to-use Compogo component that provides a SQL query builder. It automatically:\n\n  - Registers Config and Generator in the DI container\n  - Applies configuration during Configuration phase\n  - Makes the generator available for repositories and services\n\nUsage:\n\n\tcompogo.WithComponents(\n\t    db_client.Component,           // database client (provides driver name)\n\t    db_sql_generator.Component,    // SQL query builder\n\t    // ... driver components (postgres, mysql, etc.)\n\t)\n\nThe driver name is automatically taken from db-client configuration and used to select the appropriate SQL dialect.\n\nIn your repository component:\n\n\ttype UserRepository struct {\n\t    db        db_client.Client\n\t    generator *goqu.DialectWrapper\n\t}\n\n\tfunc NewUserRepository(container container.Container) (*UserRepository, error) {\n\t    var repo UserRepository\n\t    err := container.Invoke(func(db db_client.Client, gen *goqu.DialectWrapper) {\n\t        repo = UserRepository{db: db, generator: gen}\n\t    })\n\t    return \u0026repo, err\n\t}\n\n## Functions\n\n```go\nfunc NewGenerator(config *Config, informer logger.Informer) (*goqu.DialectWrapper, error)\n```\nNewGenerator creates a new goqu dialect wrapper for the configured database driver. It performs the following steps:\n\n 1. Looks up the dialect alias for the configured driver\n 2. Returns a goqu.DialectWrapper ready for building SQL queries\n\nThe generator should be used in repositories to construct type-safe SQL queries.\n\nExample:\n\n\ttype UserRepository struct {\n\t    db        db_client.Client\n\t    generator *goqu.DialectWrapper\n\t}\n\n\tfunc (r *UserRepository) GetUsers(ctx context.Context) ([]User, error) {\n\t    query := r.generator.From(\"users\").Where(goqu.C(\"active\").IsTrue())\n\t    sql, _, _ := query.ToSQL()\n\t    return r.db.QueryContext(ctx, sql)\n\t}\n\n```go\nfunc Registration(driverName string, alias string)\n```\nRegistration registers a new database driver and its goqu dialect alias. This function should be called during driver package initialization. The dialect will then be available for use via the generator component.\n\nExample (in postgres driver):\n\n\tfunc init() {\n\t    db_sql_generator.Registration(Postgres, \"postgres\")\n\t}\n\n## Types\n\n```go\ntype Config struct {\n\tDriver string\n}\n```\n\n```go\nfunc Configuration(config *Config) *Config\n```\n\n```go\nfunc NewConfig() *Config\n```\n\n","path":"github.com/Compogo/db-sql-generator","name":"db_sql_generator","synopsis":"","isRedistributable":true}
