jaguar_postgres 2.1.4 copy "jaguar_postgres: ^2.1.4" to clipboard
jaguar_postgres: ^2.1.4 copied to clipboard

outdated

A postgres interceptor for jaguar

jaguar_postgres #

A Postgres interceptor for Jaguar.

Usage #

Creating the pool #

Create an instance of PostgresPool. Supply essential database configuration. By default, PostgresPool builds on a SharedPool. Supply minPoolSize and maxPoolSize to control pool size.

final postgresPool = PostgresPool('jaguar_learn',
    password: 'dart_jaguar', minPoolSize: 5, maxPoolSize: 10);

Declaring the interceptor #

PostgresPool exposes injectInterceptor method to interceptor a route and add PostgreSQLConnection instance to it.

Future<void> pgInterceptor(Context ctx) => postgresPool.injectInterceptor(ctx);

Intercepting routes #

Add the pgInterceptor interceptor to the route chain.

@Controller()
@Intercept(const [pgInterceptor])
class PostgresExampleApi {
  // TODO Add routes ...
}

Getting and using connection #

In the route handler, get PostgreSQLConnection using getVariable<pg.PostgreSQLConnection> method of route Context.

  @GetJson()
  Future<List<Map>> readAll(Context ctx) async {
    pg.PostgreSQLConnection db = ctx.getVariable<pg.PostgreSQLConnection>();
    List<Map<String, Map<String, dynamic>>> values =
        await db.mappedResultsQuery("SELECT * FROM posts;");
    return values.map((m) => m.values.first).toList();
  }
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A postgres interceptor for jaguar

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

conn_pool, jaguar, postgres

More

Packages that depend on jaguar_postgres