Skip to content

feat: orm package #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6ba8ed6
feat(orm): initial package update
Kazi-Waseef-5002812 Jul 6, 2023
1dc065f
feat(orm): orm structure
Kazi-Waseef-5002812 Jul 7, 2023
9a6c652
feat(orm): updated api structure and dir structure
Kazi-Waseef-5002812 Jul 8, 2023
328df7e
feat(orm): updated api structure
Kazi-Waseef-5002812 Jul 11, 2023
e956feb
feat(orm): updated where api to take into account and and or
Kazi-Waseef-5002812 Jul 11, 2023
cedaee8
Merge branch 'main' into feat/orm
exaby73 Nov 17, 2023
8123b46
rebase
kaziwaseef Dec 19, 2023
65005e5
feat: added tests for getArcadeOrmInstance
exaby73 Nov 17, 2023
08418ca
feat: updated api for converters and adapter
kaziwaseef Nov 21, 2023
053c159
feat: added nvim.lua to gitignore
kaziwaseef Nov 21, 2023
11dfc8f
feat: added adapter transaction tests
kaziwaseef Nov 21, 2023
d83234e
feat: added create tests
kaziwaseef Nov 23, 2023
9129db4
chore: refactored create test
kaziwaseef Nov 23, 2023
2af04dc
feat: delete test
kaziwaseef Dec 19, 2023
1d69281
feat: test scripts
kaziwaseef Dec 19, 2023
358776a
feat: update docs
kaziwaseef Dec 20, 2023
667ac80
feat: update table and column definition
kaziwaseef Dec 21, 2023
0c8db37
feat: create to insert
kaziwaseef Dec 21, 2023
1852f90
feat: updated where implementation
kaziwaseef Dec 22, 2023
a5f9917
feat: moved to mixins
kaziwaseef Dec 22, 2023
39408b3
feat: updated example
kaziwaseef Dec 22, 2023
180778e
feat: where update
kaziwaseef Dec 22, 2023
2c1bd0e
Merge branch 'main' into feat/orm
exaby73 Dec 24, 2023
f01df45
feat: update test
kaziwaseef Dec 25, 2023
ca8032a
feat: raw test
kaziwaseef Dec 25, 2023
c927326
feat: raw test fail case
kaziwaseef Jan 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.vscode
.dart_tool/
.idea
.nvimrc
pubspec_overrides.yaml
melos_dartseid.iml
.DS_Store
.fvm
.nvim.lua
2 changes: 2 additions & 0 deletions .nvim.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vim.opt.tabstop = 2
vim.opt.shiftwidth = 2
12 changes: 12 additions & 0 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,16 @@ packages:
scripts:
analyze:
run: dart analyze

format:
exec: dart format lib

test:
exec: dart test
packageFilters:
scope: '*'

testArcadeOrm:
exec: dart test --reporter=expanded --chain-stack-traces
packageFilters:
scope: arcade_orm
2 changes: 1 addition & 1 deletion melos_arcade.iml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>
</module>
1 change: 1 addition & 0 deletions packages/arcade/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ pubspec.lock

.idea/

melos_arcade.iml
# Generated files in example
example/**/*.g.dart
16 changes: 0 additions & 16 deletions packages/arcade/melos_arcade.iml

This file was deleted.

9 changes: 9 additions & 0 deletions packages/arcade_orm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

# Avoid committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock

melos_arcade_orm.iml
3 changes: 3 additions & 0 deletions packages/arcade_orm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

- Initial version.
39 changes: 39 additions & 0 deletions packages/arcade_orm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.

For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).

For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->

TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.

## Features

TODO: List what your package can do. Maybe include images, gifs, or videos.

## Getting started

TODO: List prerequisites and provide or point to information on how to
start using the package.

## Usage

TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.

```dart
const like = 'sample';
```

## Additional information

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
1 change: 1 addition & 0 deletions packages/arcade_orm/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:lint/analysis_options.yaml
208 changes: 208 additions & 0 deletions packages/arcade_orm/example/api/basic.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
import 'dart:async';

import 'package:arcade_orm/arcade_orm.dart';
import 'package:arcade_orm/src/query/include.dart';
import 'package:arcade_orm/src/query/mixins/sort.dart';
import 'package:arcade_orm/src/query/select.dart';
import 'package:arcade_orm/src/query/where.dart';

typedef OptionsRecord = ({String? name, String? host, int? port});

class ArcadeOrmMockAdapter
implements ArcadeOrmAdapterBase<OptionsRecord, String> {
@override
late ArcadeOrm orm;
@override
final OptionsRecord? options;

@override
final String connection;

ArcadeOrmMockAdapter({
required this.connection,
this.options,
});

@override
Future<void> init() {
// TODO: implement init
throw UnimplementedError();
}

@override
ArcadeOrmTransaction transaction() {
// TODO: implement transaction
throw UnimplementedError();
}

@override
void setArcadeOrmInstance(ArcadeOrm orm) {
this.orm = orm;
}

@override
FutureOr<void> close() {
// TODO: implement close
throw UnimplementedError();
}

@override
Future<Map<String, dynamic>> operate(
{required TableOperator operator,
required ArcadeOrmTransaction? transaction,
required bool isVerbose,
String? rawSql,
List<Map<String, dynamic>>? rawNoSqlAggregate,
Map<String, dynamic>? rawNoSqlAggregateOptions,
Map<String, dynamic>? rawParams,
WhereExpressionNode? whereParams,
WhereExpressionNode? havingParams,
List<Map<String, SelectParam>> selectParams = const [],
List<IncludeParam> includeParams = const [],
List<String> groupParams = const [],
List<Map<String, SortDirection>> sortParams = const [],
Map<String, dynamic> updateWithParams = const {},
List<Map<String, dynamic>> insertWithParams = const [],
int? limit,
int? skip}) {
// TODO: implement operate
throw UnimplementedError();
}
}

class UserTable extends ArcadeOrmTableSchema {
UserTable(super.orm);

@override
final String tableName = "user";

static const String id = "id";
static const String name = "name";
static const String email = "email";
static const String age = "age";
static const String profileId = "profileId";

@override
Map<String, ColumnMeta> schema = const {
id: ColumnInt(),
name: ColumnString(),
email: ColumnString(),
age: ColumnInt(),
profileId: ColumnInt(),
};

@override
Map<String, ArcadeTableIndexRecord> index = {
name: (1, unique: null),
};

@override
Map<String, ArcadeOrmRelationshipRecord> relations = const {
"profile": (
type: ArcadeOrmRelationshipType.hasOne,
table: ProfileTable.$tableName,
localKey: profileId,
foreignKey: ProfileTable.id,
),
};
}

class ProfileTable extends ArcadeOrmTableSchema {
ProfileTable(super.orm);

static const String $tableName = "profile";

@override
String tableName = $tableName;

static const String id = "id";
static const String bio = "bio";

@override
Map<String, ColumnMeta> schema = {};
}

late final UserTable userTable;
late final ProfileTable profileTable;

Future<dynamic> orming() async {
final orm = await ArcadeOrm.init(
adapter: ArcadeOrmMockAdapter(connection: ""),
);

userTable = UserTable(orm);
profileTable = ProfileTable(orm);

final trx = userTable.transaction();
await trx.start();
userTable.findOne(transaction: trx);
trx.commit();
trx.rollback();

final data = await userTable.transaction().start(
(trx) async {
final r = userTable.findOne(transaction: trx)
..where({
UserTable.id: inList([1, 2, 4]),
})
..where({UserTable.id: eq(10)})
..where(
and([
{
UserTable.name: like("%aa"),
UserTable.id: inList([1, 2, 4]),
},
{UserTable.name: eq("2")},
]),
)
..where(
or([
{
UserTable.name: like("%aa"),
UserTable.id: between(1, 200),
}
]),
)
..select({
UserTable.name: show(),
UserTable.id: hide(),
"nom": field(UserTable.name),
"avg": avg(UserTable.age),
"count": count(UserTable.name),
"countD": count("DISTINCT(${UserTable.name})"),
"countD2": countDistinct(UserTable.name),
"x": distinct(UserTable.name),
"max": max(UserTable.age),
})
..include(
profileTable,
on: UserTable.profileId,
where: and([
{ProfileTable.bio: notEq(null)},
{ProfileTable.bio: notEq("")},
]),
joinType: JoinOperation.left,
)
..group(UserTable.id)
..sort({UserTable.name: SortDirection.asc})
..limit(10)
..skip(0);

Future<String> fromJsonFn(Map<String, dynamic> j) async {
return "";
}

final result = await r.exec(fromJson: fromJsonFn);

return switch (result) {
ExecResultData(data: final data) => data,
ExecResultFailure(exception: final _) => await () async {
throw Exception("I am basic");
}()
};
},
);

// more orming
return data;
}
4 changes: 4 additions & 0 deletions packages/arcade_orm/lib/arcade_orm.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export 'src/adapter.dart';
export 'src/core.dart';
export 'src/query.dart';
export 'src/table.dart';
Loading