Skip to content
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

feat: orm package #2

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: update test
  • Loading branch information
kaziwaseef committed Dec 25, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit f01df4519561e98d1168cdd97962ea3f3ba6cd4f
2 changes: 1 addition & 1 deletion packages/arcade_orm/lib/src/adapter.dart
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ abstract interface class ArcadeOrmAdapterBase<T extends Record, U> {
List<IncludeParam> includeParams = const [],
List<String> groupParams = const [],
List<Map<String, SortDirection>> sortParams = const [],
List<Map<String, dynamic>> updateWithParams = const [],
Map<String, dynamic> updateWithParams = const {},
List<Map<String, dynamic>> insertWithParams = const [],
int? limit,
int? skip,
4 changes: 2 additions & 2 deletions packages/arcade_orm/lib/src/query/mixins/update.dart
Original file line number Diff line number Diff line change
@@ -2,9 +2,9 @@ import 'package:meta/meta.dart';

mixin UpdateMixin {
@protected
final List<Map<String, dynamic>> $updateWithParams = [];
final Map<String, dynamic> $updateWithParams = {};

void updateWith(Map<String, dynamic> value) {
$updateWithParams.add(value);
$updateWithParams.addAll(value);
}
}
6 changes: 3 additions & 3 deletions packages/arcade_orm/test/src/query/delete_test.dart
Original file line number Diff line number Diff line change
@@ -101,7 +101,7 @@ void main() {
includeParams: any(named: "includeParams"),
groupParams: [],
sortParams: [],
updateWithParams: [],
updateWithParams: {},
insertWithParams: [],
),
).captured;
@@ -137,7 +137,7 @@ void main() {
includeParams: captureAny(named: "includeParams"),
groupParams: [],
sortParams: [],
updateWithParams: [],
updateWithParams: {},
insertWithParams: [],
),
).captured;
@@ -192,7 +192,7 @@ void main() {
includeParams: [],
groupParams: [],
sortParams: [],
updateWithParams: [],
updateWithParams: {},
insertWithParams: [],
),
).captured;
4 changes: 2 additions & 2 deletions packages/arcade_orm/test/src/query/insert_test.dart
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ void main() {
includeParams: [],
groupParams: [],
sortParams: [],
updateWithParams: [],
updateWithParams: {},
insertWithParams: [
{"name": "foo", "age": 20},
{"email": "[email protected]"},
@@ -123,7 +123,7 @@ void main() {
includeParams: [],
groupParams: [],
sortParams: [],
updateWithParams: [],
updateWithParams: {},
insertWithParams: [
{"name": "foo", "age": 20},
],
155 changes: 107 additions & 48 deletions packages/arcade_orm/test/src/query/update_test.dart
Original file line number Diff line number Diff line change
@@ -51,6 +51,7 @@ void main() {
operator: TableOperator.update,
transaction: null,
isExplain: false,
whereParams: any(named: "whereParams"),
updateWithParams: any(named: "updateWithParams"),
),
).thenAnswer(
@@ -64,7 +65,7 @@ void main() {
reset(mockTransaction);
});

test("operate", () async {
test("operate where", () async {
final arcadeOrm = await ArcadeOrm.init(
adapter: mockAdapter,
);
@@ -96,60 +97,118 @@ void main() {
includeParams: [],
groupParams: [],
sortParams: [],
updateWithParams: any(named: "updateWithParams"),
insertWithParams: [],
),
).captured;

final capturedWhereParams =
(captured.first as WhereExpressionNode).toMap();

final andExpr = capturedWhereParams[WhereExpressionOperator.and.name]
as List<Map<String, dynamic>>;

expect(
andExpr.first[UserTable.name],
equals(WhereParam(operator: WhereOperator.eq, value: "bar")),
);
expect(
andExpr.last[UserTable.age],
equals(WhereParam(operator: WhereOperator.gt, value: 20)),
);
});

test("operate updateWith", () async {
final arcadeOrm = await ArcadeOrm.init(
adapter: mockAdapter,
);
final table = UserTable(arcadeOrm);
final updateQuery = table.update()
..where(
and([
{
UserTable.name: eq("bar"),
UserTable.age: gt(20),
}
]),
)
..updateWith({
UserTable.name: "foo",
UserTable.age: 20,
})
..updateWith({
UserTable.age: 30,
UserTable.email: "[email protected]",
});

await updateQuery.exec();

final captured = verify(
() => mockAdapter.operate(
operator: TableOperator.update,
transaction: null,
isExplain: false,
whereParams: any(named: "whereParams"),
// havingParams: [],
selectParams: [],
includeParams: [],
groupParams: [],
sortParams: [],
updateWithParams: captureAny(named: "updateWithParams"),
insertWithParams: [],
),
).captured;

// print(
// const JsonEncoder.withIndent(" ")
// .convert((captured[1] as WhereExpressionNode).toMap()),
// );
final updateWithParams = captured.first as Map<String, dynamic>;

expect(
updateWithParams,
equals({
UserTable.name: "foo",
UserTable.age: 30,
UserTable.email: "[email protected]",
}),
);
});

test("data", () async {
final arcadeOrm = await ArcadeOrm.init(
adapter: mockAdapter,
);
final table = UserTable(arcadeOrm);
final udpateQuery = table.update()
..updateWith({"name": "foo", "age": 20});
final data = await udpateQuery.exec();
expect(data, isA<ExecResultData>());
expect((data as ExecResultData).data, equals({"nUpdated": 1}));
});

// test("data", () async {
// final arcadeOrm = await ArcadeOrm.init(
// adapter: mockAdapter,
// );
// final table = UserTable(arcadeOrm);
// final insertQuery = table.insert()
// ..insertWith({"name": "foo", "age": 20})
// ..insertWith({"email": "[email protected]"});
// final data = await insertQuery.exec();
// expect(data, isA<ExecResultData>());
// expect((data as ExecResultData).data, equals({"nInserted": 1}));
// });

// test("operate with transaction", () async {
// when(() => mockTransaction.start())
// .thenAnswer((_) async => Future.value());
// final arcadeOrm = await ArcadeOrm.init(
// adapter: mockAdapter,
// );
// final table = UserTable(arcadeOrm);
// final trx = table.transaction();
// await trx.start();
// final insertQuery = table.insert(transaction: trx)
// ..insertWith({"name": "foo", "age": 20});
// await insertQuery.exec();
// verify(
// () => mockAdapter.operate(
// operator: TableOperator.insert,
// transaction: trx,
// isExplain: false,
// whereParams: [],
// havingParams: [],
// selectParams: [],
// includeParams: [],
// groupParams: [],
// sortParams: [],
// updateWithParams: [],
// insertWithParams: [
// {"name": "foo", "age": 20},
// ],
// ),
// ).called(1);
// });
test("operate with transaction", () async {
when(() => mockTransaction.start())
.thenAnswer((_) async => Future.value());
final arcadeOrm = await ArcadeOrm.init(
adapter: mockAdapter,
);
final table = UserTable(arcadeOrm);
final trx = table.transaction();
await trx.start();
final insertQuery = table.update(transaction: trx)
..updateWith({"name": "foo", "age": 20});
await insertQuery.exec();
verify(
() => mockAdapter.operate(
operator: TableOperator.update,
transaction: trx,
isExplain: false,
whereParams: any(named: "whereParams"),
selectParams: [],
includeParams: [],
groupParams: [],
sortParams: [],
updateWithParams: {"name": "foo", "age": 20},
),
).called(1);
});
});
});
}