सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
PSQLite एक Flutter पैकेज है जो SQLite डेटाबेस के साथ काम करने को सरल बनाता है एक स्पष्ट और स्केलेबल इंटरफ़ेस प्रदान करके। यह SQLite कार्यक्षमता को लपेटता है ताकि Android, iOS और macOS पर Flutter एप्लिकेशन में डेटाबेस ऑपरेशन अधिक उपलब्ध हों। विकासकर्ताओं के लिए डिज़ाइन किया गया है जो स्थानीय डेटा स्थायित्व के लिए साफ़, आसान उपयोग वाला समाधान चाहते हैं, PSQLite बॉयलरप्लेट कोड को कम करता है जबकि प्रदर्शन और विश्वसनीयता बनाए रखता है। पैकेज सामान्य डेटाबेस कार्यों जैसे क्वेरी, इनसर्ट, अपडेट और डिलीट को सीधे APIs के माध्यम से समर्थन करता है।
उपयोग
मोबाइल एप्स में स्थानीय डेटा भंडारण
ऑफलाइन-प्रथम एप्लिकेशन फीचर्स
उपयोगकर्ता पसंद का प्रबंधन
डेटाबेस माइग्रेशन
संरचित डेटा कैश करना
मुख्य विशेषताएँ
सरल, स्पष्ट एपीआई
प्लेटफॉर्म के लिए समर्थन (Android, iOS, macOS)
बड़े प्रोजेक्ट्स के लिए स्केलेबल डिजाइन
एम्बेडेड क्वेरी हैंडलिंग
हल्का और कार्यक्षम
इनके लिए उपयुक्त
स्थानीय SQL स्थायित्व की आवश्यकता वाले Flutter विकासकर्ता
ऑफलाइन डेटा एक्सेस की आवश्यकता वाले प्रोजेक्ट
संरचित डेटा की आवश्यकता वाले ऐप्स
विकासक अनुभव पर ध्यान केंद्रित टीमें
विचार योग्य बातें
मूलभाव एसक्यूएल की समझ की आवश्यकता है
केवल SQLite तक सीमित
कोई निर्मित एन्क्रिप्शन नहीं
जटिल स्कीमा के लिए अतिरिक्त सेटअप की आवश्यकता हो सकती है
बादल सिंक किए गए डेटा के लिए उपयुक्त नहीं
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
PSQLite
Easily manipulate sqlite databases in Dart using this package. The designed objects structure is as follows:
TableDb: Defines a table in a database. It consists of a collection of ColumnDb objects and a table name.
ColumnDb: Defines a column of a database table. A TableDb object will be made up of a collection of ColumnDb objects.
FieldTypeDb: Defines the type of the value of a column of a table in a database. SQLite does not have a separate Boolean storage class. Instead, Boolean values are stored as integers 0 (false) and 1 (true).
ObjectStored: All objects that intend to be stored in SQLite databases should extend the ObjectStored class.
PSQLite: Encapsulates a database that is made up of a TableDb and a database name.
FilterDb: Defining a filter to make requests to PSQLite will allow us not to have to bring you all the SQLite fields and filter manually, optimizing SQLite queries through the use of filters.
ConditionDb: Allows you to define the type of condition of a filter.
Usage example
In the following example you will see how to create a user database.
Import psqlite.dart
import'package:psqlite/psqlite.dart';
Create a User
User class that represents the object that we are going to store.
Any object that is going to be ported to SQLite requires extending the ObjectStored class.
This will force us to override the toMap and getPrimaryKey methods.
import'package:psqlite/psqlite.dart';
classUserextendsObjectStored{
finalString _id;
String _name;
String _lastName;
int _age;
User(this._id, this._name, this._lastName, this._age);
User.fromJson(this._id, this._name, this._lastName, this._age);
StringgetId() => _id;
StringgetName() => _name;
StringgetLastName() => _lastName;
intgetAge() => _age;
voidsetName(String name) => _name = name;
voidsetLastName(String lastName) => _lastName = lastName;
voidsetAge(int age) => _age = age;
@overrideStringtoString() =>
'User{_id: $_id, _name: $_name, _lastName: $_lastName, _age: $_age}';
// The keys must correspond to the names of the columns in the database.@overrideMap<String, dynamic> toMap() {
return {'id': _id, 'name': _name, 'lastName': _lastName, 'age': _age};
}
@overrideStringgetPrimaryKey() => _id;
@overridebooloperator ==(Object other) {
if (other is! User) returnfalse;
if (_id != other._id) returnfalse;
if (_name != other._name) returnfalse;
if (_lastName != other._lastName) returnfalse;
if (_age != other._age) returnfalse;
returntrue;
}
@overrideintget hashCode {
var result = 17;
result = 37 * result + _id.hashCode;
result = 37 * result + _name.hashCode;
result = 37 * result + _lastName.hashCode;
result = 37 * result + _age.hashCode;
return result;
}
}
Create a User Storage Service
The easiest way to encapsulate the data persistence of the User object that we have created is by creating a wrapper service.
Inside we will create the columns of the table and the name of the database.
The mockedDatabase parameter will allow us to perform unit tests on our service.
For simplicity and in order to create FilterDb type objects, the parameterized use of the column names is recommended.
In this case, an enumerator has been used for this example called UserColumnName.
Now we can make requests to our User Storage Service from anywhere in the application.
Create a User Storage Service
You can create a single object:
final storageService = UserStorageService.init();
Or you can get the shared instance with singleton pattern:
final storageService = UserStorageService.shared;
Add a new User in SQLite
You can add a new user using our user storage service:
final storageService = UserStorageService.init();
final user = User("1", "Liam", "Neeson", 18);
await storageService.addUser(user);
Update a stored User in SQLite
You can update a stored user, in this example first we add a new user and then we are going to update it:
final storageService = UserStorageService.init();
// User add partUser user = User("1", "Liam", "Neeson", 18);
await storageService.addUser(user);
// Update user part
user.setLastName(finalLastName);
await storageService.updateUser(user);
Get the list of Users stored in SQLite
You can get the complete list of users stored:
final storageService = UserStorageService.init();
await storageService.getListOfUsers();
Get a list of filtered users
We can obtain a list of filtered elements. To do this we create a list of filters that we want to apply: