Skip to content

Commit 442e07c

Browse files
rodneyrodney
authored andcommitted
Added more insert options
1 parent 9dce486 commit 442e07c

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,21 @@ SQL.select().from('aircraft').where('tail_number').contains('N%').orderBy('model
1111
1. Exact knowledge of SQL syntax is unecessary, auto-competion will provide guidance
1212
2. No need to contruct cumbersome SQL strings
1313
3. Results in much clearner "pure-dart" code
14-
4. Does not require Flutter, can be used for CLI and Server applications of Dart
14+
4. Does not require Flutter, can be used for CLI and Server applications of Dart
15+
16+
## Examples
17+
18+
```dart
19+
// SELECT * FROM aircraft
20+
SQL.select().from('aircraft').toString();
21+
22+
// SELECT id, model, year FROM aircraft
23+
SQL.select(['id', 'model', 'year']).from('aircraft').toString();
24+
25+
// INSERT INTO aircraft (model, year) VALUES ("SR22", "2014")
26+
Map<String, dynamic> values = {"model": "SR22", "year": "2014"};
27+
SQL.insert().into('aircraft').values(values).toString();
28+
29+
// DELETE FROM aircraft WHERE model = "SR22"'
30+
SQL.delete().from('aircraft').where('model').eq("SR22").toString();
31+
```

example/main.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,11 @@ void main() {
66

77
// SELECT id, model, year FROM aircraft
88
SQL.select(['id', 'model', 'year']).from('aircraft').toString();
9+
10+
// INSERT INTO aircraft (model, year) VALUES ("SR22", "2014")
11+
Map<String, dynamic> values = {"model": "SR22", "year": "2014"};
12+
SQL.insert().into('aircraft').values(values).toString();
13+
14+
// DELETE FROM aircraft WHERE model = "SR22"'
15+
SQL.delete().from('aircraft').where('model').eq("SR22").toString();
916
}

lib/src/sql_default_values.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import 'package:dart_sql/src/sql_writer.dart';
2+
3+
class SQLDefaultValues extends SQLWriter {
4+
SQLDefaultValues(SQLWriter parent) : super(parent);
5+
6+
@override
7+
void writeTo(StringSink sink) {
8+
sink.write('DEFAULT VALUES');
9+
}
10+
}

lib/src/sql_into.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:dart_sql/dart_sql.dart';
2+
import 'package:dart_sql/src/sql_default_values.dart';
13
import 'package:dart_sql/src/sql_values.dart';
24
import 'package:dart_sql/src/sql_writer.dart';
35

@@ -6,12 +8,25 @@ class SQLInto extends SQLWriter {
68

79
String tableName;
810

11+
String asName;
12+
913
SQLValues values(Map<String, dynamic> values) {
1014
return SQLValues(values: values, parent: this);
1115
}
1216

17+
SQLSelectQuery select([List<String> projection]) {
18+
return SQLSelectQuery(projection: projection, parent: this);
19+
}
20+
21+
SQLDefaultValues defaultValues() {
22+
return SQLDefaultValues(this);
23+
}
24+
1325
@override
1426
void writeTo(StringSink sink) {
1527
sink.write('INTO $tableName ');
28+
if (asName != null) {
29+
sink.write('AS $asName ');
30+
}
1631
}
1732
}

0 commit comments

Comments
 (0)