Skip to content

Add function getConnection() to Application for database. #168

@zoujiaqing

Description

@zoujiaqing

You can use it like code:

module app.controller.IndexController;

import hunt.framework;

class IndexController : Controller
{

    mixin MakeController;

    @Action
    string index()
    {
        auto connection = app().database().getConnection();

        auto stmt = conn.createStatement();
        stmt.prepare("SELECT * FROM user WHERE username = :username AND age = :age LIMIT 10");
        stmt.setParameter("username", "zoujiaqing");
        stmt.setParameter("age", 18);

        foreach(row; stmt.query())
        {
            writeln(row["username"]);
        }

        return "";
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions