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

Implem call to NOW() #3007

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft

Implem call to NOW() #3007

wants to merge 1 commit into from

Conversation

Nirsu
Copy link

@Nirsu Nirsu commented May 14, 2024

Hello o/
This is my first open source contribution.
I wanted to implement a function to call the NOW() function in postgres.

Problem:
Try to understand how to have createdAt with a default value

Resolution:
Create this function in my server, but could be in the lib

Copy link
Owner

@simolus3 simolus3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, and congratulations on your first contribution!

The change looks good to me, but we need a test to verify that it keeps working. You could add one to this file. Tests there have access to the eval function which takes an expression and runs it on the postgres server. So you could write a test calling await eval(now()) and then verifies that the time we get back is close to DateTime.now() in Dart.

@Nirsu Nirsu marked this pull request as draft May 14, 2024 21:16
@Nirsu
Copy link
Author

Nirsu commented May 15, 2024

Thanks for the message,

I've tried to implement tests but I can't run the tests locally
I'm in the drift_postgres folder, run the docker run -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres postgres command in one terminal and dart test -j 1 in another.

But I got this error on all the tests

SocketException: The remote computer refused the network connection.
   (OS Error: The remote computer refused the network connection.
  , errno = 1225), address = localhost, port = 56908
  dart:io                                                         Socket.connect
  package:postgres/src/v3/connection.dart 237:31                  PgConnectionImplementation._connect
  package:postgres/src/v3/connection.dart 200:35                  PgConnectionImplementation.connect
  package:postgres/postgres.dart 214:39                           Connection.open
  package:drift_postgres/src/pg_database.dart 16:30               new PgDatabase.<fn>
  package:drift_postgres/src/pg_database.dart 62:32               _PgDelegate.open
  package:drift/src/runtime/executor/helpers/engines.dart 431:22  DelegatedDatabase.ensureOpen.<fn>
  ===== asynchronous gap ===========================
  package:drift/src/runtime/api/connection_user.dart 162:55       DatabaseConnectionUser.doWhenOpened.<fn>
  ===== asynchronous gap ===========================
  test\drift_postgres_test.dart 29:5                              PgExecutor.clearDatabaseAndClose
  ===== asynchronous gap ===========================
  test\types_test.dart 20:5                                       main.<fn>


To run this test again: C:\Dev\flutter\bin\cache\dart-sdk\bin\dart.exe test test\types_test.dart -p vm --plain-name "(tearDownAll)"
01:19 +1 -30: Some tests failed.
```

@simolus3
Copy link
Owner

Hm I've never considered that this would be broken on Windows, sorry. I don't have a Windows machine at hand, but can you check whether replacing localhost with the IP as shown here does anything to fix this?

But also could this be a firewall or an outdated Docker desktop version? A friend using Windows tell me he can access containers via localhost just fine.

@Nirsu
Copy link
Author

Nirsu commented May 18, 2024

I've tried, I don't have DockerNAT when I use ipconfig
Thanks for the advice, I'll try to see and get back to you as soon as possible.

@simolus3
Copy link
Owner

simolus3 commented Jun 3, 2024

Did you have a chance to revisit this yet? I'm also happy to help with the test if you can't get the configuration to work locally.

@Nirsu
Copy link
Author

Nirsu commented Jun 4, 2024

Hey,
I've managed to run the test locally but I'd love some help with the test :)
Because unfortunately eval(now()) throws me an error on the type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants