The purpose of the MVC pattern is to separate models, views and controllers into easily manageable blocks. Accessing the database directly from a view seriously violates that idea.
That being said, you may use the database connection service:
// some/view.volt
{{ set rows = db.fetchAll("SELECT * FROM tbl") }}
{{ db.execute("INSERT INTO tbl (col) VALUES ('val')") }}
{{ set statement = db.prepare("UPDATE tbl SET col=?") }}
{{ statement.execute(['val']) }}
Using Models in the view is more tricky, you could either embed a PHP block
// some/view.volt
<?php
$mdl = SomeModel::findFirst();
?>
{{ mdl.getName() }}
or create a helper service:
// ModelHelper.php
class ModelHelper
{
public function create($modelName, array $assign=[])
{
return new $modelName($assign);
}
public function findFirst($modelName, $parameters=null) {
$a = func_get_args();
$modelName = array_shift($a);
return forward_static_call_array([$modelName,'findFirst'], $a);
}
}
// services.php
$di->set('modelHelper', function() {
return new ModelHelper;
});
// some/view.volt
{{ modelHelper.findFirst('SomeModel', ['conditions'=>'id=2'])->getName() }}