GithubHelp home page GithubHelp logo

postgresql_orm's Introduction

PostgreSql ucun orm

Postgresql ve dart ile melumat bazasi

Nece yuklenir

paketi yuklemek ucun github url'ni pubspec.yaml elave edilmelidir.

 url: github.com

Istifade

import 'package:postgres_orm/orm/transaction.dart';

import 'colums.dart';
import 'database_connection.dart';
import 'model.dart';

import 'model_dao/product.dart';
import 'model_dao/users.dart';
import 'query.dart';
import 'utils.dart';


PostgreSql connection = PostgreSql(host: "127.0.0.1",port: 5432,database: "xx",username: "xx",password: "XXXxxx");

class Users extends Model {
  String tableName = "users";
  List<Column> columns = [
    Column(name: "id", type: "INT",primaryKey: true,unique: true,isSerial: true),
    Column(name: "username", type: "TEXT",unique: true),
    Column(name: "first_name",type: "TEXT"),
    Column(name: "last_name", type: "TEXT"),
  ];

  Users() : super() {
    super.tableName = this.tableName;
    super.columns = this.columns;
    super.connection = connection;
  }
}

class Category extends Model{
  String table = "category";
  List<Column> columns = [
    Column(name: "id", type: "INT",isSerial: true,primaryKey: true),
    Column(name: "name", type: "TEXT"),
  ];

  Category():super(){
    super.tableName = this.table;
    super.columns = this.columns;
    super.connection = connection;
  }
}


class Product extends Model {
  String tableName = "product";
  List<Column> columns = [
    Column(name: "id", type: "INT",primaryKey: true,unique: true,isSerial: true),
    Column(name: "product_name", type: "TEXT",),
    Column(name: "price",type: "REAL",),
    Column(name: "user_id", type: "INT",foreignKey: true,referencesTable: "users"),
    Column(name: "category", type: "INT",foreignKey: true,referencesTable: "category")
  ];

  Product() : super() {
    super.tableName = this.tableName;
    super.columns = this.columns;
    super.connection = connection;
  }
}

main() async {
    Users user =  Users();
    await user.createTable();
    Category category = Category();
    await category.createTable();
    Product product = Product();
    await product.createTable();

   await user.insert(["qewq","cerkez","alisan"]);

  user.createClass();
  category.createClass();
  product.createClass();

  UsersDAO alisan = UsersDAO(username: "userAlisan", first_name: "alisan", last_name: "cerkez");
  CategoryDAO cat = CategoryDAO( name: "kitab");

  ProductDAO prod = ProductDAO(product_name: "java",price: 14.5,category: 1,user_id: 1);

  product.insert(prod.modelToList());
  Utils u = new Utils();
  print(u.isCreatedDirectory().then((value) => print(value)));


  UsersDAO ferid = new UsersDAO(username: "araz", first_name: "ferid", last_name: "Necefov");

  await user.insert(ferid.modelToList());
  await user.delete(id: 10);
  print(user.selectAll());
  print(Query.insert(ferid.modelToList(), user.tableName, user.columns));

     Acid.transaction(connection, (var ctx) async{

      CategoryDAO kitab = CategoryDAO(name: "kitab");
      await ctx.query(Query.insert(kitab.modelToList(), category.tableName, category.columns));
  });



   var x = await user.get(id: 1).then((value) => value);
  UsersDAO use = UsersDAO.fromList(x);
  print(use.id);
  print(use.id);

  var xc = await category.get(id: 1).then((value) => value);
  CategoryDAO yc = CategoryDAO.fromList(xc);
  print(yc.name);
}

postgresql_orm's People

Contributors

charkaz avatar

Watchers

 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.