mirror of https://github.com/AMT-Cheif/drift.git
Prepare release for sqlparser 0.3.0
This commit is contained in:
parent
fb68dc0888
commit
c4f321748a
|
@ -1,3 +1,9 @@
|
|||
## 0.3.0
|
||||
- parse compound select statements
|
||||
- scan comment tokens
|
||||
- experimental auto-complete engine (only supports a tiny subset based on the grammar only)
|
||||
- some features that are specific to moor
|
||||
|
||||
## 0.2.0
|
||||
- Parse `CREATE TABLE` statements
|
||||
- Extract schema information from parsed create table statements with `SchemaFromCreateTable`.
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
# sqlparser
|
||||
|
||||
An sql parser and static analyzer, written in pure Dart. At the moment, this library only targets
|
||||
the sqlite dialect and some advanced features aren't supported yet.
|
||||
Sql parser and static analyzer written in Dart. At the moment, this library targets the
|
||||
sqlite dialect only.
|
||||
|
||||
## Features
|
||||
This library can parse most statements and perform type analysis for parameters and returned
|
||||
columns. It supports joins, `group by`, nested sql statements, updates and deletes, and more.
|
||||
### Just parsing
|
||||
This library can parse most sql statements and perform static analysis. We can resolve
|
||||
what type a column in a `SELECT` statement has, infer types for variables, find
|
||||
semantic errors and more.
|
||||
|
||||
This library supports most features, including joins, `group by`, nested and compound sql
|
||||
statements, window functions and foreign keys.
|
||||
### Using the parser
|
||||
You can parse the abstract syntax tree of sqlite statements with `SqlEngine.parse`.
|
||||
```dart
|
||||
import 'package:sqlparser/sqlparser.dart';
|
||||
|
@ -34,7 +38,7 @@ Given information about all tables and a sql statement, this library can:
|
|||
tables / columns, uses undefined functions, etc.)
|
||||
|
||||
To use the analyzer, first register all known tables via `SqlEngine.registerTable`. Then,
|
||||
`SqlEngine.analyze(sql)` gives you an `AnalysisContext` which contains an annotated ast and information
|
||||
`SqlEngine.analyze(sql)` gives you an `AnalysisContext` which contains an annotated AST and information
|
||||
about errors. The type of result columns and expressions can be inferred by using
|
||||
`AnalysisContext.typeOf()`. Here's an example:
|
||||
|
||||
|
@ -65,7 +69,6 @@ package to generate type-safe methods from sql.
|
|||
Most on this list is just not supported yet because I didn't found a use case for
|
||||
them yet. If you need them, just leave an issue and I'll try to implement them soon.
|
||||
|
||||
- Compound select statements (`UNION` / `INTERSECT`) are not supported yet
|
||||
- Common table expressions are not supported
|
||||
- Some advanced expressions, like `CAST`s aren't supported yet.
|
||||
- An `UPSERT` clause is not yet supported on insert statements
|
||||
|
|
|
@ -107,6 +107,8 @@ class SqlEngine {
|
|||
|
||||
/// Analyzes the given [node], which should be a [CrudStatement].
|
||||
/// The [AnalysisContext] enhances the AST by reporting type hints and errors.
|
||||
/// The [file] should contain the full SQL source code that was used to parse
|
||||
/// the [node].
|
||||
///
|
||||
/// The analyzer needs to know all the available tables to resolve references
|
||||
/// and result columns, so all known tables should be registered using
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: sqlparser
|
||||
description: Parses sqlite statements and performs static analysis on them
|
||||
version: 0.2.0
|
||||
version: 0.3.0
|
||||
homepage: https://github.com/simolus3/moor/tree/develop/sqlparser
|
||||
#homepage: https://moor.simonbinder.eu/
|
||||
issue_tracker: https://github.com/simolus3/moor/issues
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
import 'package:sqlparser/sqlparser.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../data.dart';
|
||||
|
||||
void main() {
|
||||
test('reports column count mismatch in compound select query', () {
|
||||
final engine = SqlEngine()..registerTable(demoTable);
|
||||
final result = engine.analyze('SELECT * FROM demo UNION SELECT 1');
|
||||
|
||||
expect(result.errors, hasLength(1));
|
||||
final error = result.errors.single;
|
||||
|
||||
expect(error.type, AnalysisErrorType.compoundColumnCountMismatch);
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue