Angel
Primary version
Primary version
  • Introduction
  • Migration from Angel 1.1.x
    • Rationale - Why a new Version?
    • Framework Changelog
    • 2.0.0 Migration Guide
  • ORM
    • About
    • Basic Functionality
    • Relations
    • Migrations
    • NoSQL
    • PostgreSQL
  • Guides
    • Getting Started
    • Basic Routing
    • Dependency Injection Patterns
    • Installation & Setup
    • Without the Boilerplate
    • Requests & Responses
    • Dependency Injection
    • Basic Routing
    • Request Lifecycle
    • Middleware
    • Controllers
    • Parsing Request Bodies
    • Using Plug-ins
    • Rendering Views
    • Service Basics
    • REST Client
    • Testing
    • Error Handling
    • Pattern Matching and Parameter
    • Command Line
    • Writing a Plugin
  • Example Projects
  • YouTube Tutorials
  • Ecosystem
  • Packages
    • Authentication
    • CORS
    • Database-Agnostic Relations
    • Configuration
    • Database Adapters
      • MongoDB
      • RethinkDB
      • JSON File-based
      • ORM
    • Front-end
      • Mustache Templates
      • Jael template engine
        • Github
        • Basics
        • Custom Elements
        • Strict Resolution
        • Directive: declare
        • Directive: for-each
        • Directive: extend
        • Directive: if
        • Directive: include
        • Directive: switch
      • compiled_mustache-based engine
      • html_builder-based engine
      • Markdown template engine
      • Using Angel with Angular
    • Hot Reloading
    • Pagination
    • Polling
    • Production Utilities
    • Reverse Proxy
    • Router
    • Serialization
    • Service Seeder
    • Static Files
    • Security
    • Server-sent Events
    • shelf Integration
    • Task Engine
    • User Agents
    • Validation
    • Websockets
Powered by GitBook
On this page
  1. ORM

PostgreSQL

PostgreSQL support is provided by way of package:angel_orm_postgres. The PostgreSQLExecutor implements QueryExecutor, and takes care of running prepared queries, and passing values to the database server.

angel init projects using the ORM include helpers like this to load app configuration into a database connection:

Future<void> configureServer(Angel app) async {
  var connection = await connectToPostgres(app.configuration);
  await connection.open();

  app
    ..container.registerSingleton<QueryExecutor>(PostgreSQLExecutor(connection))
    ..shutdownHooks.add((_) => connection.close());
}

Future<PostgreSQLConnection> connectToPostgres(Map configuration) async {
  var postgresConfig = configuration['postgres'] as Map ?? {};
  var connection = PostgreSQLConnection(
      postgresConfig['host'] as String ?? 'localhost',
      postgresConfig['port'] as int ?? 5432,
      postgresConfig['database_name'] as String ??
          Platform.environment['USER'] ??
          Platform.environment['USERNAME'],
      username: postgresConfig['username'] as String,
      password: postgresConfig['password'] as String,
      timeZone: postgresConfig['time_zone'] as String ?? 'UTC',
      timeoutInSeconds: postgresConfig['timeout_in_seconds'] as int ?? 30,
      useSSL: postgresConfig['use_ssl'] as bool ?? false);
  return connection;

Typically, you'll want to use app configuration to create the connection, rather than hard coding values.

PreviousNoSQLNextGuides

Last updated 6 years ago