Finalize renaming

This commit is contained in:
Simon Binder 2019-03-09 17:01:55 +01:00
parent 62900a93a9
commit 4d80ff77c9
No known key found for this signature in database
GPG Key ID: B807FDF954BA00CF
18 changed files with 73 additions and 65 deletions

View File

@ -4,8 +4,8 @@ dart:
- stable
env:
- PKG="sally"
- PKG="sally_generator"
- PKG="moor"
- PKG="moor_generator"
script: ./tool/mono_repo_wrapper.sh
@ -17,5 +17,5 @@ branches:
cache:
directories:
- "$HOME/.pub-cache"
- sally/.dart_tool/build
- sally_generator/.dart_tool/build
- moor/.dart_tool/build
- moor_generator/.dart_tool/build

View File

@ -1,12 +1,12 @@
# Sally
[![Build Status](https://travis-ci.com/simolus3/sally.svg?token=u4VnFEE5xnWVvkE6QsqL&branch=master)](https://travis-ci.com/simolus3/sally)
# Moor
[![Build Status](https://travis-ci.com/simolus3/moor.svg?token=u4VnFEE5xnWVvkE6QsqL&branch=master)](https://travis-ci.com/simolus3/moor)
Sally is an easy to use and safe way to persist data for Flutter apps. It features
moor is an easy to use and safe way to persist data for Flutter apps. It features
a fluent Dart DSL to describe tables and will generate matching database code that
can be used to easily read and store your app's data. It also features a reactive
API that will deliver auto-updating streams for your queries.
- [Sally](#sally)
- [moor](#moor)
* [Getting started](#getting-started)
+ [Adding the dependency](#adding-the-dependency)
+ [Declaring tables](#declaring-tables)
@ -27,34 +27,34 @@ API that will deliver auto-updating streams for your queries.
## Getting started
### Adding the dependency
First, let's add sally to your project's `pubspec.yaml`. The library is not yet
First, let's add moor to your project's `pubspec.yaml`. The library is not yet
out on pub, so you'll need to use the git repository for now:
```yaml
dependencies:
sally:
moor:
git:
url: https://github.com/simolus3/sally.git
path: sally/
url: https://github.com/simolus3/moor.git
path: moor/
dev_dependencies:
sally_generator:
moor_generator:
git:
url: https://github.com/simolus3/sally.git
path: sally_generator/
url: https://github.com/simolus3/moor.git
path: moor_generator/
build_runner: ^1.2.0
```
We're going to use the `sally_flutter` library to specify tables and access the database. The
`sally_generator` library will take care of generating the necessary code so the
We're going to use the `moor_flutter` library to specify tables and access the database. The
`moor_generator` library will take care of generating the necessary code so the
library knows how your table structure looks like.
### Declaring tables
You can use the DSL included with this library to specify your libraries with simple
dart code:
```dart
import 'package:sally_flutter/sally_flutter.dart';
import 'package:moor_flutter/moor_flutter.dart';
// assuming that your file is called filename.dart. This will give an error at first,
// but it's needed for sally to know about the generated code
// but it's needed for moor to know about the generated code
part 'filename.g.dart';
// this will generate a table called "todos" for us. The rows of that table will
@ -66,7 +66,7 @@ class Todos extends Table {
IntColumn get category => integer().nullable()();
}
// This will make sally generate a class called "Category" to represent a row in this table.
// This will make moor generate a class called "Category" to represent a row in this table.
// By default, "Categorie" would have been used because it only strips away the trailing "s"
// in the table name.
@DataClassName("Category")
@ -76,9 +76,9 @@ class Categories extends Table {
TextColumn get description => text()();
}
// this annotation tells sally to prepare a database class that uses both of the
// this annotation tells moor to prepare a database class that uses both of the
// tables we just defined. We'll see how to use that database class in a moment.
@UseSally(tables: [Todos, Categories])
@Usemoor(tables: [Todos, Categories])
class MyDatabase {
}
@ -90,14 +90,14 @@ executed. Instead, the generator will take a look at your table classes to figur
This won't work if the body of your tables is not constant. This should not be problem, but please be aware of this as you can't put logic inside these classes.
### Generating the code
Sally integrates with the dart `build` system, so you can generate all the code needed with
moor integrates with the dart `build` system, so you can generate all the code needed with
`flutter packages pub run build_runner build`. If you want to continously rebuild the code
whever you change your code, run `flutter packages pub run build_runner watch` instead.
After running either command once, sally generator will have created a class for your
After running either command once, moor generator will have created a class for your
database and data classes for your entities. To use it, change the `MyDatabase` class as
follows:
```dart
@UseSally(tables: [Todos, Categories])
@Usemoor(tables: [Todos, Categories])
class MyDatabase extends _$MyDatabase {
// we tell the database where to store the data with this constructor
MyDatabase() : super(FlutterQueryExecutor.inDatabaseFolder(path: 'db.sqlite'));
@ -128,7 +128,7 @@ class MyDatabase extends _$MyDatabase {
### Select statements
You can create `select` statements by starting them with `select(tableName)`, where the
table name
is a field generated for you by sally. Each table used in a database will have a matching field
is a field generated for you by moor. Each table used in a database will have a matching field
to run queries against. A query can be run once with `get()` or be turned into an auto-updating
stream using `watch()`.
#### Where
@ -232,7 +232,7 @@ Stream<List<CategoryWithCount>> categoriesWithCount() {
```
## Migrations
Sally provides a migration API that can be used to gradually apply schema changes after bumping
moor provides a migration API that can be used to gradually apply schema changes after bumping
the `schemaVersion` getter inside the `Database` class. To use it, override the `migration`
getter. Here's an example: Let's say you wanted to add a due date to your todo entries:
```dart
@ -273,7 +273,7 @@ available from your main database class. Consider the following code:
```dart
part 'todos_dao.g.dart';
// the _TodosDaoMixin will be created by sally. It contains all the necessary
// the _TodosDaoMixin will be created by moor. It contains all the necessary
// fields for the tables. The <MyDatabase> type annotation is the database class
// that should use this dao.
@UseDao(tables: [Todos])
@ -292,7 +292,7 @@ class TodosDao extends DatabaseAccessor<MyDatabase> with _TodosDaoMixin {
}
}
```
If we now change the annotation on the `MyDatabase` class to `@UseSally(tables: [Todos, Categories], daos: [TodosDao])`
If we now change the annotation on the `MyDatabase` class to `@Usemoor(tables: [Todos, Categories], daos: [TodosDao])`
and re-run the code generation, a getter `todosDao` can be used to access the instance of that dao.
## TODO-List and current limitations

View File

@ -3,7 +3,7 @@
part of 'example.dart';
// **************************************************************************
// moorGenerator
// MoorGenerator
// **************************************************************************
class Category {

View File

@ -3,7 +3,7 @@
part of 'todos.dart';
// **************************************************************************
// moorGenerator
// MoorGenerator
// **************************************************************************
class TodoEntry {

View File

@ -1,7 +1,7 @@
# moor
# Moor
[![Build Status](https://travis-ci.com/simolus3/moor.svg?token=u4VnFEE5xnWVvkE6QsqL&branch=master)](https://travis-ci.com/simolus3/moor)
moor is an easy to use and safe way to persist data for Flutter apps. It features
Moor is an easy to use and safe way to persist data for Flutter apps. It features
a fluent Dart DSL to describe tables and will generate matching database code that
can be used to easily read and store your app's data. It also features a reactive
API that will deliver auto-updating streams for your queries.

View File

@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 27
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
@ -38,9 +38,9 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "eu.simonbinder.moorexample.moorexample"
applicationId "eu.simonbinder.moor_example.example"
minSdkVersion 16
targetSdkVersion 27
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

View File

@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.simonbinder.moor_example.example">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

View File

@ -1,11 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.simonbinder.moorexample.moorexample">
<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
package="eu.simonbinder.moor_example.example">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
@ -14,13 +8,13 @@
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="moor_example"
android:label="example"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing

View File

@ -1,4 +1,4 @@
package eu.simonbinder.moorexample.moorexample
package eu.simonbinder.moor_example.example
import android.os.Bundle

View File

@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.simonbinder.moor_example.example">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

View File

@ -4,4 +4,4 @@ import 'package:source_gen/source_gen.dart';
import 'package:moor_generator/src/moor_generator.dart';
Builder moorBuilder(BuilderOptions _) =>
SharedPartBuilder([moorGenerator(), DaoGenerator()], 'moor');
SharedPartBuilder([MoorGenerator(), DaoGenerator()], 'moor');

View File

@ -1,17 +1,17 @@
import 'package:analyzer/dart/element/element.dart';
class moorError {
class MoorError {
final bool critical;
final String message;
final Element affectedElement;
moorError({this.critical = false, this.message, this.affectedElement});
MoorError({this.critical = false, this.message, this.affectedElement});
}
class ErrorStore {
final List<moorError> errors = [];
final List<MoorError> errors = [];
void add(moorError error) => errors.add(error);
void add(MoorError error) => errors.add(error);
bool get hasCriticalError => errors.any((e) => e.critical);
}

View File

@ -12,7 +12,7 @@ import 'package:moor_generator/src/parser/table_parser.dart';
import 'package:moor_generator/src/writer/database_writer.dart';
import 'package:source_gen/source_gen.dart';
class moorGenerator extends GeneratorForAnnotation<Usemoor> {
class MoorGenerator extends GeneratorForAnnotation<Usemoor> {
//final Map<String, ParsedLibraryResult> _astForLibs = {};
final ErrorStore errors = ErrorStore();
@ -51,7 +51,7 @@ class moorGenerator extends GeneratorForAnnotation<Usemoor> {
for (var table in tableTypes) {
if (!tableTypeChecker.isAssignableFrom(table.element)) {
errors.add(moorError(
errors.add(MoorError(
critical: true,
message: 'The type $table is not a moor table',
affectedElement: element));

View File

@ -24,7 +24,7 @@ const String errorMessage = 'This getter does not create a valid column that '
'columns are formed. If you have any questions, feel free to raise an issue.';
class ColumnParser extends ParserBase {
ColumnParser(moorGenerator generator) : super(generator);
ColumnParser(MoorGenerator generator) : super(generator);
SpecifiedColumn parse(MethodDeclaration getter) {
/*
@ -39,7 +39,7 @@ class ColumnParser extends ParserBase {
final expr = returnExpressionOfMethod(getter);
if (!(expr is FunctionExpressionInvocation)) {
generator.errors.add(moorError(
generator.errors.add(MoorError(
affectedElement: getter.declaredElement,
message: errorMessage,
critical: true,
@ -69,7 +69,7 @@ class ColumnParser extends ParserBase {
switch (methodName) {
case functionNamed:
if (foundExplicitName != null) {
generator.errors.add(moorError(
generator.errors.add(MoorError(
critical: false,
affectedElement: getter.declaredElement,
message:
@ -79,7 +79,7 @@ class ColumnParser extends ParserBase {
foundExplicitName =
readStringLiteral(remainingExpr.argumentList.arguments.first, () {
generator.errors.add(moorError(
generator.errors.add(MoorError(
critical: false,
affectedElement: getter.declaredElement,
message:

View File

@ -10,7 +10,7 @@ class Parser {
}
class ParserBase {
final moorGenerator generator;
final MoorGenerator generator;
ParserBase(this.generator);
@ -18,7 +18,7 @@ class ParserBase {
final body = method.body;
if (!(body is ExpressionFunctionBody)) {
generator.errors.add(moorError(
generator.errors.add(MoorError(
affectedElement: method.declaredElement,
critical: true,
message:

View File

@ -11,7 +11,7 @@ import 'package:moor_generator/src/moor_generator.dart'; // ignore: implementati
import 'package:recase/recase.dart';
class TableParser extends ParserBase {
TableParser(moorGenerator generator) : super(generator);
TableParser(MoorGenerator generator) : super(generator);
SpecifiedTable parse(ClassElement element) {
final sqlName = _parseTableName(element);
@ -58,7 +58,7 @@ class TableParser extends ParserBase {
tableNameDeclaration.node as MethodDeclaration);
final tableName = readStringLiteral(returnExpr, () {
generator.errors.add(moorError(
generator.errors.add(MoorError(
critical: true,
message:
'This getter must return a string literal, and do nothing more',
@ -79,7 +79,7 @@ class TableParser extends ParserBase {
as MethodDeclaration;
final body = ast.body;
if (body is! ExpressionFunctionBody) {
generator.errors.add(moorError(
generator.errors.add(MoorError(
affectedElement: primaryKeyGetter,
message: 'This must return a set literal using the => syntax!'));
return null;
@ -105,7 +105,7 @@ class TableParser extends ParserBase {
parsedPrimaryKey.add(column);
}
} else {
generator.errors.add(moorError(
generator.errors.add(MoorError(
affectedElement: primaryKeyGetter,
message: 'This must return a set literal!'));
return null;

View File

@ -8,7 +8,7 @@ import 'package:build_test/build_test.dart';
void main() async {
LibraryElement testLib;
moorGenerator generator;
MoorGenerator generator;
setUpAll(() async {
testLib = await resolveSource(r'''
@ -48,7 +48,7 @@ void main() async {
});
setUp(() {
generator = moorGenerator();
generator = MoorGenerator();
generator
..columnParser = ColumnParser(generator)
..tableParser = TableParser(generator);