Serverside Database Object Models for simple data manipulation using MySQL/PGSQL without having to write SQL
inspired by Ruby on Rails models
This requires the use of Dartabase Migration
Tested on
Dart SDK version 1.16.0
Uses
MYSQL via sqljocky version 0.14.1
PGSQL via postgresql version 0.3.3
####Dartabase Documentation 1.Dartabase Migration - How to install and use
2.Dartabase Model - How to how to install and use - current
####Dartabase Tutorials 1.How to create a Dartabase supported app from scratch
2.How to create a Dartabase supported app for an existing database
After you have successfully finished setting up 'Dartabase Migration'
Install Dartabase Model the usual pubspec way
Inside your project, at the beginning of the main method insert
Model.initiate("path-to-your-project");
now it should look kinda like this:
-----dataserver.dart--START--
library dataServer;
import 'package:dartabase_model/dartabase_model.dart';
main(){
Model.initiate("C:\\darttestproject\\DartabaseServer");
... your code
}
-----dataserver.dart--END--
Imagine you have ONLY created one database table named 'account'
with the column 'name'
You have to extend all classes that you want to connected to the database
with 'Model'
in this case we create a class Account with id, name, created_at and updated_at
-----account.dart--START--
part of dataServer;
class Account extends Model{
num id;// database column autogenerated by migration
String name;
DateTime created_at;// database column autogenerated by migration
DateTime updated_at;// database column autogenerated by migration
}
-----account.dart--END--
-----dataserver.dart--START--
library dataServer;
import 'package:dartabase_model/dartabase_model.dart';
part "account.dart";
main(){
Model.initiate("C:\\darttestproject\\DartabaseServer");
... your code
}
-----dataserver.dart--END--
Future save()
returns String "created" or "updated"
var process = await player.save();
if(process == "created" || process == "updated"){
//your code
}
Future findBy(String column,var value)
returns an (player) object if one exists
else
returns null
var player = await player.findBy("name","tim");
if(player != null){
//your code
}
Future findById(var id)
accepted type of id is (String || int || num)
returns an (player) object if one exists
else
returns null
var player = await player.findById("3");
if(player != null){
//your code
}
Future findAllBy(String column, var value)
returns a list of (player) objects if one exists
else
returns empty list
List players = await player.findAllBy("name","tim");
if(!players.isEmpty){
//your code
}
Future findAll()
returns a list of all (player) objects if one exists
else
returns empty list
List players = await player.findAll();
if(!players.isEmpty){
//your code
}
Future delete()
deletes the object //TODO and all its relations
await player.delete();
//your code
Future receive(object)
creates relation between the two objects (player and character)
var result = await player.receive(character);
//your code
Future hasOne(object)
returns an (character) object if one exists
else
returns null
var character = await player.hasOne(new Character());
if(character != null){
//your code
}
Future hasMany(object)
returns a list of (character) objects if one exists
else
returns empty list
List characters = await player.hasMany(new Character());
if(!characters.isEmpty){
//your code
}
Future hasOneWith(object,String column,String value)
returns an (character) object if one exists
else
returns null
var character = await player.hasOneWith(new Character(),'level','3');
if(character != null){
//your code
}
Future hasManyWith(object,String column,String value)
Returns a list of (character) objects if one exists
else
Returns empty list
List characters = await player.hasManyWith(new Character(),'level','3');
if(!characters.isEmpty){
//your code
}
Future remove(object)
remove relation between the two objects (player and character)
var result = await player.remove(character);
//your code
*test functionality in bigger project
*add more features like implementing and removing dependencies
*add automated tests
*and much more
Please let me know about bugs you find and or improvements/features you would like to see in future.
ENJOY
1.1.3 -updated core to 0.5.2
1.1.0 -updated core to 0.5.1
-refactored code to use dynamic relation divider _2_ or _to_ depending on existing database tables
-added blob support in toJSON function
1.0.1 -updated core to 0.4.1
1.0.0 -cleaner code using await and async
-set min dart sdk to 1.8.0
-updated to work with dartabase core 0.4.0
-updated postgresql to 0.3.3
-updated sqlJocky to 0.14.1
0.7.0 -updated to work with dartabase core 0.3.0
0.6.3 -added ssl support! see Migration readme ->config file
-improved speed via single connection instead of multi pools
-updated postgresql to 0.2.13
0.6.2 -updated sqlJocky to 0.11.0
-fixed problem due to generation of table column created_at using now().
should work in mysql version >= 5.0 //tested on producktion 5.0 and 5.5
//pls file me a bug, if you still have problems creating tables via migration.
0.6.1 -added link to tutorial in readme.md
0.6.0 -required Migration 0.6.x
-fix major bug
apperently CamelCaseObject conversion to table_name was not done correct
now possible to habe server model with multiple capital letters
e.g. "UserPicture.dart" converts to table name "user_picture"
before it converted to "userpicture" which did not exist
-adapt dartabaseCore
0.5.6 -added toJson() for custom classes extending model
-changed return value for save()
-accept string or int for findBy()
-fix bool problem when saving
-moved Version to CHANGELOG.md
0.5.5 -fixed issue with database type bool
0.5.4 -fix: return null instead of empty list in mysql when single object was requested
0.5.3 -added findAll()
-fixed code comments
0.5.2 -corrected spelling
0.5.1 -fixed README.md
0.5.0 -required Migration 0.5.x
see Migration readme.md
-added relations between tables
0.4.1 -adapted model to work with old and new migration files
0.4.0 -adapted model for migration 0.4.0 see compatibility below
0.3.0 -fixed possible crash in < 0.3.0 with mysql adapter,
-changed model method_names to methodNames (Dart Style Guide)
0.2.1 -added delete function to remove object from database
0.2.0 -added support for autogenerated created_at and updated_at columns
see changelog for dartabase migration 0.3.0
0.1.1 -fix discription
0.1.0 -ready for Dart 1.0
Add this to your package's pubspec.yaml file:
dependencies:
dartabase_model: "^1.1.3"
You can install packages from the command line:
with pub:
$ pub get
Alternatively, your editor might support pub get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:dartabase_model/dartabase_model.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
1.1.3 | Sep 21, 2016 |
|
|
1.1.2 | Aug 16, 2016 |
|
|
1.1.1 | Aug 15, 2016 |
|
|
1.1.0 | Aug 14, 2016 |
|
|
1.0.0 | Jun 6, 2016 |
|
|
0.7.0 | Aug 8, 2014 |
|
|
0.6.3 | May 20, 2014 |
|
|
0.6.2 | May 13, 2014 |
|
|
0.6.1 | May 12, 2014 |
|
|
0.6.0 | May 9, 2014 |
|
|
We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
8 | / 100 |
Health:
Code health derived from static analysis.
[more]
|
37 | / 100 |
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
40 | / 100 |
Overall score:
Weighted score of the above.
[more]
|
23 |
Detected platforms: web, other
Primary library:
package:dartabase_model/dartabase_model.dart
with components:mirrors
.
Fix analysis and formatting issues.
Analysis or formatting checks reported 3 errors 15 hints.
Strong-mode analysis of
lib/dartabase_model.dart
failed with the following error:line: 687 col: 25
The getter 'max' isn't defined for the class 'Row'.
Maintain an example.
Create a short demo in the
example/
directory to show how to use this package. Common file name patterns include:main.dart
,example.dart
or you could also usedartabase_model.dart
.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=1.8.0 <2.0.0 | ||
dartabase_core | ^0.5.2 | 0.5.2 | 1.0.0 |
json_object | >=1.0.18+2 <1.1.0 | 1.0.19+1 | |
postgresql | ^0.3.3 | 0.3.4+1 | |
sqljocky | ^0.14.1 | 0.14.1 | |
Transitive dependencies | |||
charcode | 1.1.1 | ||
convert | 1.1.1 | 2.0.1 | |
crypto | 0.9.2+1 | 2.0.2+1 | |
dev_string_converter | 0.2.0 | ||
logging | 0.11.3+1 | ||
options_file | 0.11.0 | ||
typed_data | 1.1.5 |