42 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
import 'dart:io';
 | 
						|
 | 
						|
import 'package:notes/savesystem/path.dart';
 | 
						|
import 'package:sqflite/sqflite.dart';
 | 
						|
 | 
						|
class NoteFile {
 | 
						|
  late Database _db;
 | 
						|
  String filepath;
 | 
						|
 | 
						|
  Database db() {
 | 
						|
    return _db;
 | 
						|
  }
 | 
						|
 | 
						|
  NoteFile(this.filepath);
 | 
						|
 | 
						|
  Future<void> init() async {
 | 
						|
    final path = (await getSavePath()).path + Platform.pathSeparator + filepath;
 | 
						|
    _db = await openDatabase(
 | 
						|
      path,
 | 
						|
      onCreate: (db, version) {
 | 
						|
        return db.execute(
 | 
						|
          'CREATE TABLE strokes(id integer primary key autoincrement, color INTEGER, elevation INTEGER);'
 | 
						|
          'CREATE TABLE points(id integer primary key autoincrement, x INTEGER, y INTEGER, thickness REAL, strokeid INTEGER)',
 | 
						|
        );
 | 
						|
      },
 | 
						|
      // Set the version. This executes the onCreate function and provides a
 | 
						|
      // path to perform database upgrades and downgrades.
 | 
						|
      version: 1,
 | 
						|
    );
 | 
						|
  }
 | 
						|
 | 
						|
  void delete() {
 | 
						|
    // todo remove db file
 | 
						|
  }
 | 
						|
 | 
						|
  Future<void> close() async {
 | 
						|
    // shrink the db file size
 | 
						|
    await _db.execute('VACUUM');
 | 
						|
    _db.close();
 | 
						|
  }
 | 
						|
}
 |