Skip to content

Commit 521a7f0

Browse files
committed
Extract database access objects out of authpass-cloud.
1 parent 3cd2cf1 commit 521a7f0

File tree

11 files changed

+696
-43
lines changed

11 files changed

+696
-43
lines changed

analysis_options.yaml

Lines changed: 169 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,173 @@
33
# see https://github.com/dart-lang/pedantic#enabled-lints.
44
include: package:pedantic/analysis_options.yaml
55

6-
# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
7-
# Uncomment to specify additional rules.
8-
# linter:
9-
# rules:
10-
# - camel_case_types
11-
126
analyzer:
13-
# exclude:
14-
# - path/to/excluded/files/**
7+
exclude:
8+
- lib/**/*.g.dart
9+
strong-mode:
10+
implicit-casts: false
11+
implicit-dynamic: false
12+
errors:
13+
# treat missing required parameters as a warning (not a hint)
14+
missing_required_param: warning
15+
# treat missing returns as a warning (not a hint)
16+
missing_return: warning
17+
# allow having TODOs in the code
18+
todo: ignore
19+
20+
linter:
21+
rules:
22+
# these rules are documented on and in the same order as
23+
# the Dart Lint rules page to make maintenance easier
24+
# http://dart-lang.github.io/linter/lints/
25+
26+
# HP mostly in sync with https://github.com/flutter/flutter/blob/master/analysis_options.yaml
27+
28+
- always_declare_return_types
29+
- always_put_control_body_on_new_line
30+
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
31+
- always_require_non_null_named_parameters
32+
# - always_specify_types
33+
- annotate_overrides
34+
# - avoid_annotating_with_dynamic # not yet tested
35+
# - avoid_as
36+
- avoid_bool_literals_in_conditional_expressions
37+
# - avoid_catches_without_on_clauses # not yet tested
38+
# - avoid_catching_errors # not yet tested
39+
# - avoid_classes_with_only_static_members # not yet tested
40+
# - avoid_double_and_int_checks # only useful when targeting JS runtime
41+
- avoid_empty_else
42+
- avoid_field_initializers_in_const_classes
43+
- avoid_function_literals_in_foreach_calls
44+
# - avoid_implementing_value_types # not yet tested
45+
- avoid_init_to_null
46+
# - avoid_js_rounded_ints # only useful when targeting JS runtime
47+
- avoid_null_checks_in_equality_operators
48+
# - avoid_positional_boolean_parameters # not yet tested
49+
# - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
50+
- avoid_relative_lib_imports
51+
- avoid_renaming_method_parameters
52+
- avoid_return_types_on_setters
53+
# - avoid_returning_null # not yet tested
54+
# - avoid_returning_null_for_future # not yet tested
55+
- avoid_returning_null_for_void
56+
# - avoid_returning_this # not yet tested
57+
# - avoid_setters_without_getters # not yet tested
58+
# - avoid_shadowing_type_parameters # not yet tested
59+
# - avoid_single_cascade_in_expression_statements # not yet tested
60+
- avoid_slow_async_io
61+
- avoid_types_as_parameter_names
62+
# - avoid_types_on_closure_parameters # not yet tested
63+
- avoid_unused_constructor_parameters
64+
- avoid_void_async
65+
- await_only_futures
66+
- camel_case_extensions
67+
- camel_case_types
68+
- cancel_subscriptions
69+
# - cascade_invocations # not yet tested
70+
# - close_sinks # not reliable enough
71+
# - comment_references # blocked on https://github.com/flutter/flutter/issues/20765
72+
# - constant_identifier_names # https://github.com/dart-lang/linter/issues/204
73+
- control_flow_in_finally
74+
- curly_braces_in_flow_control_structures
75+
# - diagnostic_describe_all_properties # not yet tested
76+
- directives_ordering
77+
- empty_catches
78+
- empty_constructor_bodies
79+
- empty_statements
80+
# - file_names # not yet tested
81+
# - flutter_style_todos TODO(HP)
82+
- hash_and_equals
83+
- implementation_imports
84+
# - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
85+
- iterable_contains_unrelated_type
86+
# - join_return_with_assignment # not yet tested
87+
- library_names
88+
- library_prefixes
89+
# - lines_longer_than_80_chars # not yet tested
90+
- list_remove_unrelated_type
91+
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
92+
- no_adjacent_strings_in_list
93+
- no_duplicate_case_values
94+
- non_constant_identifier_names
95+
# - null_closures # not yet tested
96+
# - omit_local_variable_types # opposite of always_specify_types
97+
# - one_member_abstracts # too many false positives
98+
# - only_throw_errors # https://github.com/flutter/flutter/issues/5792
99+
- overridden_fields
100+
- package_api_docs
101+
- package_names
102+
- package_prefixed_library_names
103+
# - parameter_assignments # we do this commonly
104+
- prefer_adjacent_string_concatenation
105+
- prefer_asserts_in_initializer_lists
106+
# - prefer_asserts_with_message # not yet tested
107+
- prefer_collection_literals
108+
- prefer_conditional_assignment
109+
- prefer_const_constructors
110+
- prefer_const_constructors_in_immutables
111+
- prefer_const_declarations
112+
- prefer_const_literals_to_create_immutables
113+
# - prefer_constructors_over_static_methods # not yet tested
114+
- prefer_contains
115+
# - prefer_double_quotes # opposite of prefer_single_quotes
116+
- prefer_equal_for_default_values
117+
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
118+
- prefer_final_fields
119+
- prefer_final_in_for_each
120+
- prefer_final_locals
121+
- prefer_for_elements_to_map_fromIterable
122+
- prefer_foreach
123+
# - prefer_function_declarations_over_variables # not yet tested
124+
- prefer_generic_function_type_aliases
125+
# - prefer_if_elements_to_conditional_expressions # not yet tested
126+
- prefer_if_null_operators
127+
- prefer_initializing_formals
128+
- prefer_inlined_adds
129+
# - prefer_int_literals # not yet tested
130+
# - prefer_interpolation_to_compose_strings # not yet tested
131+
- prefer_is_empty
132+
- prefer_is_not_empty
133+
- prefer_iterable_whereType
134+
# - prefer_mixin # https://github.com/dart-lang/language/issues/32
135+
# - prefer_null_aware_operators # disable until NNBD, see https://github.com/flutter/flutter/pull/32711#issuecomment-492930932
136+
- prefer_single_quotes
137+
- prefer_spread_collections
138+
- prefer_typing_uninitialized_variables
139+
- prefer_void_to_null
140+
# - provide_deprecation_message # not yet tested
141+
# - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
142+
- recursive_getters
143+
- slash_for_doc_comments
144+
# - sort_child_properties_last # not yet tested
145+
- sort_constructors_first
146+
- sort_pub_dependencies
147+
- sort_unnamed_constructors_first
148+
- test_types_in_equals
149+
- throw_in_finally
150+
# - type_annotate_public_apis # subset of always_specify_types
151+
- type_init_formals
152+
# - unawaited_futures # https://github.com/flutter/flutter/issues/5793
153+
# - unnecessary_await_in_return # not yet tested
154+
- unnecessary_brace_in_string_interps
155+
- unnecessary_const
156+
- unnecessary_getters_setters
157+
# - unnecessary_lambdas # https://github.com/dart-lang/linter/issues/498
158+
- unnecessary_new
159+
- unnecessary_null_aware_assignments
160+
- unnecessary_null_in_if_null_operators
161+
- unnecessary_overrides
162+
#- unnecessary_parenthesis HP: I like parenthesis :-)
163+
- unnecessary_statements
164+
- unnecessary_this
165+
- unrelated_type_equality_checks
166+
# - unsafe_html # not yet tested
167+
- use_full_hex_values_for_flutter_colors
168+
# - use_function_type_syntax_for_parameters # not yet tested
169+
- use_rethrow_when_possible
170+
# - use_setters_to_change_properties # not yet tested
171+
# - use_string_buffers # https://github.com/dart-lang/linter/pull/664
172+
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
173+
- valid_regexps
174+
- void_checks
175+

example/postgres_utils_example.dart

Lines changed: 0 additions & 6 deletions
This file was deleted.

lib/postgres_utils.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
/// More dartdocs go here.
44
library postgres_utils;
55

6-
export 'src/postgres_utils_base.dart';
7-
8-
// TODO: Export any libraries intended for clients of this package.
6+
export 'src/config.dart';
7+
export 'src/database_access.dart';
8+
export 'src/tables/base_tables.dart';

lib/src/config.dart

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import 'dart:convert';
2+
import 'dart:io';
3+
4+
import 'package:json_annotation/json_annotation.dart';
5+
import 'package:meta/meta.dart';
6+
7+
part 'config.g.dart';
8+
9+
@JsonSerializable(anyMap: true, checked: true)
10+
class DatabaseConfig {
11+
DatabaseConfig({
12+
@required this.host,
13+
@required this.port,
14+
@required this.databaseName,
15+
@required this.username,
16+
this.password,
17+
}) : assert(host != null),
18+
assert(port != null),
19+
assert(databaseName != null),
20+
assert(username != null);
21+
22+
factory DatabaseConfig.fromJson(Map<String, dynamic> json) =>
23+
_$DatabaseConfigFromJson(json);
24+
25+
factory DatabaseConfig.defaults() =>
26+
DatabaseConfig.fromJson(_jsonFromEnvironment());
27+
Map<String, dynamic> toJson() => _$DatabaseConfigToJson(this);
28+
29+
@JsonKey(defaultValue: 'localhost')
30+
final String host;
31+
@JsonKey(defaultValue: 5432)
32+
final int port;
33+
34+
@JsonKey(defaultValue: 'authpass')
35+
final String databaseName;
36+
@JsonKey(defaultValue: 'authpass')
37+
final String username;
38+
@JsonKey(defaultValue: 'blubb')
39+
final String password;
40+
41+
DatabaseConfig copyWith({String databaseName}) => DatabaseConfig(
42+
host: host,
43+
port: port,
44+
databaseName: databaseName ?? this.databaseName,
45+
username: username,
46+
password: password,
47+
);
48+
}
49+
50+
Map<String, dynamic> _jsonFromEnvironment() {
51+
final dbConfig = Platform.environment['DBCONFIG'];
52+
if (dbConfig != null) {
53+
return json.decode(dbConfig) as Map<String, dynamic>;
54+
}
55+
return <String, dynamic>{};
56+
}

lib/src/config.g.dart

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)