Giter Site home page Giter Site logo

md-siam / isar_crud Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 3.95 MB

Isar is for local database storage in a Flutter application. Isar is No-SQL relational database.

License: MIT License

Kotlin 0.43% Swift 1.36% Objective-C 0.13% Dart 87.36% Ruby 4.57% HTML 6.15%

isar_crud's Introduction

           

Isar CRUD - YouTube

Isar is a No-SQL relational database for Flutter a application. I am using an YouTube tutorial for this project. In this tutorial we will learn the following topics:

    1. Collections
    2. Indexes
    3. CRUD
    4. Queries
    5. Full-text search
    6. Transactions
    7. Watches
    8. Schema & Collection

pubspec.yaml

dependencies:
  isar: ^2.5.0
  # contains the binaries (not required for web)
  isar_flutter_libs: ^2.5.0
  # For providing the storage path
  path_provider: ^2.0.11

dev_dependencies:
  isar_generator: ^2.5.0
  build_runner: ^2.2.0

Command to execute build runner:

 $ flutter pub run build_runner build

App Demo

Isar CRUD

Create: create_routine_page.dart

  addRoutine() async {
    final routineCollection = widget.isar.routines;
    final newRoutine = Routine()
      ..title = _titleController.text
      ..startTimeRoutine = _timeController.text
      ..day = dropdownDay
      ..category.value = dropdownValue;

    await widget.isar.writeTxn((isar) async {
      await routineCollection.put(newRoutine);
    });

    _titleController.clear();
    _timeController.clear();
    dropdownDay = 'monday';
    dropdownValue = null;

    // SnackBar for notifying the user
    final snackBar = SnackBar(
      content: Text('${_titleController.text.toString()} added!'),
      action: SnackBarAction(
        label: 'ok',
        onPressed: () => Navigator.pop(context),
      ),
    );
    ScaffoldMessenger.of(context).showSnackBar(snackBar);
  }

Read: home_page.dart

  _readRoutines() async {
    final routineCollection = widget.isar.routines;
    final getRoutines = await routineCollection.where().findAll();

    setState(() {
      routines = getRoutines;
      isLoading = false;
    });
    // print(routines![0].title);
    // print(routines![0].startTimeRoutine);
    // print(routines!.length);
  }

Update: update_routine_page.dart

  updateRoutine() async {
    final routineCollection = widget.isar.routines;
    await widget.isar.writeTxn((isar) async {
      final routine = await routineCollection.get(widget.routine.id);

      routine!
        ..title = _titleController.text
        ..startTimeRoutine = _timeController.text
        ..day = dropdownDay
        ..category.value = dropdownValue;

      await routineCollection.put(routine);

      Navigator.pop(context);
    });
  }

Delete: update_routine_page.dart

  deleteRoutine() async {
    final routineCollection = widget.isar.routines;

    await widget.isar.writeTxn((isar) async {
      routineCollection.delete(widget.routine.id);
    });

    Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => HomePage(isar: widget.isar)),
    );
  }

Searching

  searchRoutineByName(String searchName) async {
    searching = true;
    final routineCollection = widget.isar.routines;
    final searchResults =
        await routineCollection.filter().titleContains(searchName).findAll();

    setState(() {
      routines = searchResults;
      isLoading = false;
    });
  } 

Handling Transaction

A transaction is a set of operations, or a set of statements that are executed as a unit together. In short, it will involve more than one operation.

  clearAll() async {
    final routineCollection = widget.isar.routines;
    final getRoutines = await routineCollection.where().findAll();

    await widget.isar.writeTxn((isar) async {
      for (var routine in getRoutines) {
        routineCollection.delete(routine.id);
      }
    });
    setState(() {});
  }

File Pattern Inside The lib Folder

lib/
├── app/
│   ├── collections/
│   │   ├── category.dart
│   │   ├── category.g.dart
│   │   ├── routine.dart
│   │   └── routine.g.dart
│   └── pages/
│       ├── create_routine_page.dart
│       ├── home_page.dart
│       └── update_routine_page.dart
└── main.dart

isar_crud's People

Contributors

md-siam avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.