Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zoujiaqing opened this issue Oct 10, 2020 · 0 comments
Open

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

zoujiaqing opened this issue Oct 10, 2020 · 0 comments

Comments

@zoujiaqing
Copy link
Member

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 "";
    }
}
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

No branches or pull requests

1 participant