orm_plus 1.0.0 copy "orm_plus: ^1.0.0" to clipboard
orm_plus: ^1.0.0 copied to clipboard

orm_plus is a Dart ORM library that simplifies server-side development with support for MySQL and PostgreSQL. It streamlines tasks such as server setup, schema definition, and CRUD operations. With fe [...]

example/main.dart

import 'package:orm_plus/orm_plus.dart';

const bool sync = false;
const int port = 5555;
void main() async {
  try {
    Server server = Server();

    PostgresClient client = PostgresClient(host: 'localhost', database: 'test', userName: 'postgres', password: "Dharmesh@123");
    await client.connect();
    ORM orm = ORM(client: client, schemas: [userSchema], logging: true);
    await orm.sync(syncTable: sync);

    Router userRouter = Router(endPoint: '/users');

    userRouter.post("/insert", (req, res) async {
      var data = await orm.insert(
        table: "users",
        returning: true,
        data: {
          "username": "test",
          "first_name": "Test",
          "last_name": "User",
          "email": "test@mailinator.com",
          "gender": "male",
          "verify": false,
        },
      );
      return res.json({'data': data});
    });

    userRouter.delete("/delete", (req, res) async {
      var data = await orm.delete(table: "users", returning: true, where: {'id': 1});
      return res.json({'data': data});
    });

    userRouter.patch("/update", (req, res) async {
      var data = await orm.update(table: "users", returning: true, data: {'verify': true});
      return res.json({'data': data});
    });

    userRouter.get("/all", (req, res) async {
      var data = await orm.findAncCountAll(table: "users");
      return res.json({'data': data});
    });

    server.registerRouters([userRouter]);

    server.get("/", (req, res) async {
      return res.write("Server are running fine.");
    });

    server.onError((error, res) {
      res.json({'error': error..toString()});
    });

    server.listen(
      port: port,
      callback: () {
        print("Server are listening on port $port");
      },
    );
  } catch (e) {
    print("Exception: ${e.toString()}");
  }
}

Schema userSchema = Schema(
  table: "users",
  fields: {
    "id": {
      "type": DataType.SERIAL(),
      "primaryKey": true,
    },
    "username": {
      "type": DataType.STRING(50),
      "unique": true,
      "allowNull": false,
    },
    "first_name": DataType.STRING(50),
    "last_name": DataType.STRING(50),
    "gender": DataType.STRING(10),
    "email": {
      "type": DataType.STRING(100),
      "unique": true,
      "allowNull": false,
    },
    "verify": {
      "type": DataType.BOOLEAN(),
      "default": "FALSE",
      "allowNull": false,
    }
  },
);
6
likes
110
points
17
downloads

Publisher

unverified uploader

Weekly Downloads

orm_plus is a Dart ORM library that simplifies server-side development with support for MySQL and PostgreSQL. It streamlines tasks such as server setup, schema definition, and CRUD operations. With features like advanced querying, relationship management, and optional logging, orm_plus makes building scalable and efficient applications straightforward.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

archive, mime, mysql_client, postgres

More

Packages that depend on orm_plus