Remove deprecated usages of SqlEngine constructor

This commit is contained in:
Simon Binder 2020-01-07 11:40:09 +01:00
parent c5c8dc7d6d
commit a3708b7230
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
10 changed files with 37 additions and 25 deletions

View File

@ -33,7 +33,7 @@ manyColumns:
class ParseMoorFile extends BenchmarkBase {
ParseMoorFile(ScoreEmitter emitter) : super('Moor file: Parse only', emitter);
final _engine = SqlEngine(useMoorExtensions: true);
final _engine = SqlEngine.withOptions(EngineOptions(useMoorExtensions: true));
@override
void exercise() {

View File

@ -1,5 +0,0 @@
include: ../analysis_options.yaml
analyzer:
errors:
deprecated_member_use_from_same_package: ignore

View File

@ -0,0 +1 @@
../analysis_options.yaml

View File

@ -21,14 +21,19 @@ class SqlEngine {
SchemaFromCreateTable _schemaReader;
@Deprecated('Use SqlEngine.withOptions instead')
SqlEngine(
{bool useMoorExtensions = false,
{@Deprecated('Use SqlEngine.withOptions instead')
bool useMoorExtensions = false,
@Deprecated('Use SqlEngine.withOptions instead')
bool enableJson1Module = false,
@Deprecated('Use SqlEngine.withOptions instead')
bool enableFts5 = false})
: this.withOptions(_constructOptions(
// ignore: deprecated_member_use_from_same_package
moor: useMoorExtensions,
// ignore: deprecated_member_use_from_same_package
json1: enableJson1Module,
// ignore: deprecated_member_use_from_same_package
fts5: enableFts5,
));

View File

@ -4,7 +4,7 @@ import 'package:test/test.dart';
void main() {
group('resolves return types of json functions', () {
ResolveResult findResult(String expression) {
final engine = SqlEngine(enableJson1Module: true);
final engine = SqlEngine.withOptions(EngineOptions(enableJson1: true));
final result = engine.analyze('SELECT $expression;');
final select = result.root as SelectStatement;

View File

@ -63,7 +63,8 @@ void main() {
});
test('supports booleans when moor extensions are enabled', () {
final engine = SqlEngine(useMoorExtensions: true);
final engine =
SqlEngine.withOptions(EngineOptions(useMoorExtensions: true));
final stmt = engine.parse('''
CREATE TABLE foo (
a BOOL, b DATETIME, c DATE, d BOOLEAN NOT NULL

View File

@ -78,7 +78,8 @@ void main() {
});
test('can infer types for dart placeholder', () {
final ctx = (SqlEngine(useMoorExtensions: true)..registerTable(demoTable))
final ctx = (SqlEngine.withOptions(EngineOptions(useMoorExtensions: true))
..registerTable(demoTable))
.analyze(r'SELECT * FROM demo WHERE $expr');
final dartExpr =
@ -89,7 +90,8 @@ void main() {
});
test('respects explicit types for variables', () {
final ctx = SqlEngine(useMoorExtensions: true).analyze(
final ctx =
SqlEngine.withOptions(EngineOptions(useMoorExtensions: true)).analyze(
'SELECT ?',
stmtOptions: const AnalyzeStatementOptions(indexedVariableTypes: {
1: ResolvedType.bool(),

View File

@ -2,9 +2,11 @@ import 'package:sqlparser/sqlparser.dart';
import 'package:sqlparser/src/engine/autocomplete/engine.dart';
import 'package:test/test.dart';
final _moorOptions = EngineOptions(useMoorExtensions: true);
void main() {
test('suggests a CREATE an empty file', () {
final engine = SqlEngine(useMoorExtensions: true);
final engine = SqlEngine.withOptions(_moorOptions);
final parseResult = engine.parseMoorFile('');
final suggestions = parseResult.autoCompleteEngine.suggestCompletions(0);
@ -15,7 +17,7 @@ void main() {
});
test('suggests CREATE TABLE completion after CREATE', () async {
final engine = SqlEngine(useMoorExtensions: true);
final engine = SqlEngine.withOptions(_moorOptions);
final parseResult = engine.parseMoorFile('CREATE ');
final suggestions = parseResult.autoCompleteEngine.suggestCompletions(7);
@ -25,7 +27,7 @@ void main() {
});
test('suggests completions for started keywords', () {
final engine = SqlEngine(useMoorExtensions: true);
final engine = SqlEngine.withOptions(_moorOptions);
final parseResult = engine.parseMoorFile('creat');
final suggestions = parseResult.autoCompleteEngine.suggestCompletions(0);

View File

@ -1,9 +1,11 @@
import 'package:sqlparser/sqlparser.dart';
import 'package:test/test.dart';
final _fts5Options = EngineOptions(enabledExtensions: const [Fts5Extension()]);
void main() {
group('creating fts5 tables', () {
final engine = SqlEngine(enableFts5: true);
final engine = SqlEngine.withOptions(_fts5Options);
test('can create fts5 tables', () {
final result = engine.analyze('CREATE VIRTUAL TABLE foo USING '
@ -33,7 +35,7 @@ void main() {
group('type inference for function calls', () {
SqlEngine engine;
setUp(() {
engine = SqlEngine(enableFts5: true);
engine = SqlEngine.withOptions(_fts5Options);
// add an fts5 table for the following queries
final fts5Result = engine.analyze('CREATE VIRTUAL TABLE foo USING '
'fts5(bar, baz);');
@ -77,7 +79,7 @@ void main() {
group('type inference for function arguments', () {
SqlEngine engine;
setUp(() {
engine = SqlEngine(enableFts5: true);
engine = SqlEngine.withOptions(_fts5Options);
// add an fts5 table for the following queries
final fts5Result = engine.analyze('CREATE VIRTUAL TABLE foo USING '
'fts5(bar, baz);');
@ -123,7 +125,7 @@ void main() {
group('error reporting', () {
SqlEngine engine;
setUp(() {
engine = SqlEngine(enableFts5: true);
engine = SqlEngine.withOptions(_fts5Options);
// add an fts5 table for the following queries
final fts5Result = engine.analyze('CREATE VIRTUAL TABLE foo USING '
'fts5(bar, baz);');

View File

@ -93,7 +93,7 @@ void main() {
test("reports error when the statement can't be parsed", () {
// regression test for https://github.com/simolus3/moor/issues/280#issuecomment-570789454
final parsed = SqlEngine(useMoorExtensions: true)
final parsed = SqlEngine.withOptions(EngineOptions(useMoorExtensions: true))
.parseMoorFile('name: NSERT INTO foo DEFAULT VALUES;');
expect(

View File

@ -19,15 +19,19 @@ IdentifierToken identifier(String content) {
}
void testMoorFile(String moorFile, MoorFile expected) {
final parsed =
SqlEngine(useMoorExtensions: true).parseMoorFile(moorFile).rootNode;
final parsed = SqlEngine.withOptions(EngineOptions(useMoorExtensions: true))
.parseMoorFile(moorFile)
.rootNode;
enforceHasSpan(parsed);
enforceEqual(parsed, expected);
}
void testStatement(String sql, AstNode expected, {bool moorMode = false}) {
final parsed = SqlEngine(useMoorExtensions: moorMode).parse(sql).rootNode;
final parsed =
SqlEngine.withOptions(EngineOptions(useMoorExtensions: moorMode))
.parse(sql)
.rootNode;
enforceHasSpan(parsed);
enforceEqual(parsed, expected);
}