static_postgres_orm

Creator: coderz1093

Last updated:

0 purchases

static_postgres_orm Image
static_postgres_orm Images

Languages

Categories

Add to Cart

Description:

static postgres orm

A library for create a static ORM for postgres tables.
Created from templates made available by Stagehand under a BSD-style
license.
Usage #
A simple usage example:
import 'package:static_postgres_orm/static_postgres_orm.dart';
import 'package:dartz/dartz.dart';

class _DataFields extends GenericDataFields {
late final IntegerField_PG _company_id;
late final IntegerField_PG _product_id;
late final StringField_WithDefault_PG _description;
late final StringField_WithDefault_PG _code;
late final BooleanField_WithDefault_PG _is_active;
late final NumericField_WithDefault_PG _price;
late final StringField_WithDefault_PG _full_description;
late final DateField_WithDefault_PG _insert_date;
late final DateTimeField_WithDefault_PG _update_date;
late final TimeField_PG _insert_time;

_DataFields() : super() {
fields = <GenericField>[];
_createFields();
_addFields();
}

_DataFields get _backup => getBackup(this) as _DataFields;
set _backup(_DataFields v) => setBackup(this, v);

void _createFields() {
_company_id = IntegerField_PG(this, 'company_id', true, true);
_product_id = IntegerField_PG(this, 'product_id', true, true);
_code =
StringField_WithDefault_PG(this, 'code', false, false, 50, 'aloja!!!!');
_description = StringField_WithDefault_PG(
this, 'description', false, false, 200, 'produto genérico');
_is_active =
BooleanField_WithDefault_PG(this, 'is_active', false, false, false);
_price = NumericField_WithDefault_PG(this, 'price', false, false, 0);
_full_description = StringField_WithDefault_PG(
this, 'full_description', false, false, -1, 'Aloja!');
_insert_date = DateField_WithDefault_PG(
this, 'insert_date', false, false, DateTime.now());
_update_date = DateTimeField_WithDefault_PG(
this, 'update_date', false, false, DateTime.now());
_insert_time = TimeField_PG(this, 'insert_time', false, false);
}

GenericField getCooField(_DataFields origin, String field) {
return origin.fields
.firstWhere((element) => getFieldName(element) == field);
}

void _cloneField(_DataFields origin) {
fields.forEach((element) {
element.copy(getCooField(origin, getFieldName(element)));
});
}

@override
void backup() {
_backup = _DataFields();
_backup._cloneField(this);
}

@override
void restore() {
if (assigned) {
_cloneField(_backup);
finalize();
}
}

void _addFields() {
fields.add(_company_id);
fields.add(_product_id);
fields.add(_code);
fields.add(_description);
fields.add(_is_active);
fields.add(_price);
fields.add(_full_description);
fields.add(_insert_date);
fields.add(_update_date);
fields.add(_insert_time);
}
}

class Product_ORM extends PostgressORM {
static final Event _addRecord = Event();

_DataFields get _dataFields => getRecords(this)[rowIndex] as _DataFields;

IntegerField get product_id => _dataFields._product_id;
IntegerField get company_id => _dataFields._company_id;
StringField_WithDefault get description => _dataFields._description;
StringField_WithDefault get code => _dataFields._code;
BooleanField_WithDefault get is_active => _dataFields._is_active;
NumericField_WithDefault get price => _dataFields._price;
StringField_WithDefault get full_description => _dataFields._full_description;
DateField_WithDefault get insert_date => _dataFields._insert_date;
DateTimeField_WithDefault get update_date => _dataFields._update_date;
TimeField get insert_time => _dataFields._insert_time;

Product_ORM(Postgres_SqlConnection sqlConnection)
: super(sqlConnection, 'public', 'product', _addRecord) {
_addRecord.action = _executeAddRecord;

getRecords(this).add(_DataFields());
}

void _executeAddRecord() {
getRecords(this).add(_DataFields());
}

Future<Either<ErrorSqlResult, SelectSuccesSqlResult>> materialize(
int company_id, int product_id) async {
return getMaterialize(
this,
(<GenericField>[])
..add(IntegerField_PG.clone(_dataFields._company_id)
..setValue(company_id))
..add(IntegerField_PG.clone(_dataFields._product_id)
..setValue(product_id)));
}

Future<Either<ErrorSqlResult, ExecuteSuccesSqlResult>> deleteRecord(
int company_id, int product_id) async {
return getDeleteRecord(
this,
(<GenericField>[])
..add(IntegerField_PG.clone(_dataFields._company_id)
..setValue(company_id))
..add(IntegerField_PG.clone(_dataFields._product_id)
..setValue(product_id)));
}
}
copied to clipboard
Features and bugs #
Please file feature requests and bugs at the issue tracker.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.