Skip to content

Commit

Permalink
First public release.
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos committed Feb 18, 2020
1 parent b37811f commit d76d7e9
Show file tree
Hide file tree
Showing 8 changed files with 677 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ build/

# Directory created by dartdoc
doc/api/

# IDE
*.iml
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

- Initial public release.
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2016-2020, Agilord.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
A library to control a maximized number of connections to a single PostgreSQL server.

## Usage

Once you've created the `PgPool` object, you can:

- Use it as `PostgreSQLExecutionContext` (from `package:postgres`).
- Use `PgPool.run` for non-transactional batches with optional retry.
- Use `PgPool.runTx` for transactional batches with optional retry.
62 changes: 62 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# This file allows you to configure the Dart analyzer.
#
# The commented part below is just for inspiration. Read the guide here:
# https://github.com/dart-lang/sdk/tree/master/pkg/analyzer#configuring-the-analyzer

include: package:pedantic/analysis_options.yaml

analyzer:
errors:
unused_element: error
unused_import: error
unused_local_variable: error
dead_code: error
strong-mode:
implicit-casts: false

linter:
rules:
# see catalogue here: http://dart-lang.github.io/linter/lints/
- annotate_overrides
- avoid_unused_constructor_parameters
- await_only_futures
- camel_case_types
- cancel_subscriptions
- directives_ordering
# - empty_catches
- empty_statements
- hash_and_equals
- iterable_contains_unrelated_type
- list_remove_unrelated_type
- no_adjacent_strings_in_list
- no_duplicate_case_values
- non_constant_identifier_names
- only_throw_errors
- overridden_fields
- prefer_collection_literals
- prefer_conditional_assignment
- prefer_contains
- prefer_final_fields
- prefer_final_locals
- prefer_initializing_formals
- prefer_interpolation_to_compose_strings
- prefer_is_empty
- prefer_is_not_empty
- prefer_single_quotes
- prefer_typing_uninitialized_variables
- recursive_getters
- slash_for_doc_comments
- test_types_in_equals
- throw_in_finally
- type_init_formals
- unawaited_futures
- unnecessary_brace_in_string_interps
- unnecessary_getters_setters
- unnecessary_lambdas
- unnecessary_new
- unnecessary_null_aware_assignments
- unnecessary_statements
- unnecessary_this
- unrelated_type_equality_checks
- use_rethrow_when_possible
- valid_regexps
36 changes: 36 additions & 0 deletions example/example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:postgres_pool/postgres_pool.dart';

Future<void> main() async {
final pg = PgPool(
PgUrl(
host: 'localhost',
port: 5432,
database: 'test',
username: 'test',
password: 'test'),
);

final futures = <Future>[];
for (var i = 0; i < 100; i++) {

// pg.run schedules a callback function to be called when a connection
// becomes available. We are not blocking on the result yet.
final f = pg.run((c) async {
final rs = await c.query(
'SELECT COUNT(*) FROM test_table WHERE type = @type',
substitutionValues: {
'type': i,
},
);
return rs[0][0];
});

futures.add(f);
}

// We've scheduled 100 connection-using callbacks, and very likely the first
// one is already ongoing. Let's wait for all of them.
await Future.wait(futures);

await pg.close();
}
Loading

0 comments on commit d76d7e9

Please sign in to comment.