error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query_as` - postgresql

I want to send query to database, but I faced this error:
this error originates in the macro $crate::sqlx_macros::expand_query which comes from the expansion of the macro sqlx::query_as (in Nightly builds, run with -Z macro-backtrace for more info)
DATABASE_URL must be set to use query macros
I am using the Rocket framework and PostgreSQL.
Code:
#[get("/user/<uuid>", rank = 1, format = "text/plain")]
async fn user(pool: &rocket::State<PgPool>, uuid: &str) -> Result<User, Status> {
let parsed_uuid = Uuid::parse_str(uuid).map_err(|_| Status::BadRequest)?;
let user = sqlx::query_as!(User, "SELECT * FROM users WHERE uuid = $1", parsed_uuid)
.fetch_one(pool.inner())
.await;
user.map_err(|_| Status::NotFound)
}
#[launch]
async fn rocket() -> Rocket<Build> {
let our_rocket = rocket::build();
let config: Config = our_rocket
.figment()
.extract()
.expect("Incorrect Rocket.toml configuration");
let pool = PgPoolOptions::new()
.max_connections(5)
.connect(&config.database_url)
.await
.expect("Failed to connect to database");
our_rocket.manage(pool)
}
[dependencies]
rocket = { version = "0.5.0-rc.2", features = ["secrets"] }
sqlx = {version = "0.6.2", features = ["postgres","uuid", "runtime-tokio-rustls"]}
How can i solve that problem?

sqlx uses the database to check if your queries types are correct, to use it's macros you have to define the environment variable DATABASE_URL, use a .env file or provide a sqlx-data.json you can set DATABASE_URL to a database with the schema required, you can run cargo with the appropriate environment setup: DATABASE_URL="postgres://your_database_info" cargo (run|build|check|…)

Related

Execute gatling scenarios based on a boolean flag

Is it possible in Gatling to execute scenarios based on a boolean flag from properties file
application.conf
config {
isDummyTesting = true,
Test {
baseUrl = "testUrl"
userCount = 1
testUser {
CustomerLoginFeeder = "CustomerLogin.getLogin()"
Navigation = "Navigation.navigation"
}
},
performance {
baseUrl = "testUrl"
userCount = 100
testUser {
CustomerLoginFeeder = "CustomerLogin.getLogin()"
}
}
}
and in my simulation file
var flowToTest = ConfigFactory.load().getObject("config.performance.testUser").toConfig
if (ConfigFactory.load().getBoolean("config.isDummyTesting")) {
var flowToTest = ConfigFactory.load().getObject("config.Test.testUser").toConfig
}
while executing flow, i am running below code
scenario("Customer Login").exec(flowToTest)
and facing error
ERROR : io.gatling.core.structure.ScenarioBuilder
cannot be applied to (com.typesafe.config.Config)
I want if flag is true, it executes two scenarios else the other one.
I think you're making a mistake in trying to have to flow defined in the config, rather than just the flag. You can then load the value of the isDummyTesting flag and have that passed into a session variable. From there, you can use the standard gatling doIf construct to include Navigation.navigation if specified.
so in your simulation file, you can have
private val isDummyTesting = java.lang.Boolean.getBoolean("isDummyTesting")
and then in your scenario
.exec(session => session.set("isDummyTesting", isDummyTesting))
...
.exec(CustomerLogin.getLogin())
.doIf("${isDummyTesting}") {
exec(Navigation.navigation)
}

Calling a custom function in Rasa Actions

I am facing a problem in developing a chatbot using rasa .
I am trying to call a custom function in rasa action file. But i am getting an error saying "name 'areThereAnyErrors' is not defined"
here is my action class. I want to call areThereAnyErrors function from run method. Could someone please help how to resolve this?
class ActionDayStatus(Action):
def areThereAnyErrors(procid):
errormessagecursor = connection.cursor()
errormessagecursor.execute(u"select count(*) from MT_PROSS_MEAGE where pro_id = :procid and msg_T = :messageT",{"procid": procid, "messageT": 'E'})
counts = errormessagecursor.fetchone()
errorCount = counts[0]
print("error count is {}".format(errorCount))
if errorCount == 0:
return False
else:
return True
def name(self):
return 'action_day_status'
def run(self, dispatcher, tracker, domain):
import cx_Oracle
import datetime
# Connect as user "hr" with password "welcome" to the "oraclepdb" service running on this computer.
conn_str = dbconnection
connection = cx_Oracle.connect(conn_str)
cursor = connection.cursor()
dateIndicator = tracker.get_slot('requiredDate')
delta = datetime.timedelta(days = 1)
now = datetime.datetime.now()
currentDate = (now - delta).strftime('%Y-%m-%d')
print(currentDate)
cursor = connection.cursor()
cursor.execute(u"select * from M_POCESS_FILE where CREATE_DATE >= TO_DATE(:createDate,'YYYY/MM/DD') fetch first 50 rows only",{"createDate":currentDate})
all_files = cursor.fetchall()
total_number_of_files = len(all_files)
print("total_number_of_files are {}".format(total_number_of_files))
Answer given by one of the intellectuals :
https://realpython.com/instance-class-and-static-methods-demystified/ Decide whether you want a static method or class method or instance method and call it appropriately . Also when you are using connection within the function it should be a member variable or passed to the method You dont have self as a parameter so you may be intending it as a static method - but you dont have it created as such

How to use Scaldi Conditions to do default binding

I am using Scaldi with Play and Slick in my application.
I need to bind a DatabaseConfig dependency to different configurations depending on some condition.
Mode = Dev => Oracle DB
Mode = UAT => Another Oracle DB
...
Mode = Test => Local H2 DB
No Mode specified => same as Mode = Test
How do I handle the last part? I tried to do the following but it does not work.
val inDevMode = SysPropCondition(name = "mode", value = Some("dev"))
val inTestMode = SysPropCondition(name = "mode", value = Some("test")) or SysPropCondition(name = "mode", value = None)
bind [DatabaseConfig[JdbcProfile]] when (inDevMode) to new DbConfigHelper().getDecryptedConfig("gem2g") destroyWith (_.db.close)
bind [DatabaseConfig[JdbcProfile]] when (inTestMode) to DatabaseConfig.forConfig[JdbcProfile]("h2") destroyWith (_.db.close)
val inTestMode = SysPropCondition(name=MODE, value=Some("test")) or SysPropCondition(name=MODE, value=None) or
Condition(System.getProperty(MODE) == null)

Is there a working example of Akka.net Persistence with MongoDb out there anywhere?

I am attempting to configure Akka.Net with journal persistence to MongoDb but it is throwing an exception that I can't quite figure out. Is there a reference example out there anywhere I can look at to see how this is supposed to work? I would have expected the examples in the unit tests to fill this need for me but the tests are missing for the MongoDb implementation of persistence. :(
Here's the error I am getting:
Akka.Actor.ActorInitializationException : Exception during creation --->
System.TypeLoadException : Method 'ReplayMessagesAsync' in type
'Akka.Persistence.MongoDb.Journal.MongoDbJournal' from assembly
'Akka.Persistence.MongoDb, Version=1.0.5.2, Culture=neutral, PublicKeyToken=null'
does not have an implementation.
and here is my HOCON for this app:
---Edit - Thanks for the tip Horusiath; based on that I updated to this HOCON and the Sqlite provider works but the MongoDb one is still giving an error.
<![CDATA[
akka {
actor {
provider = "Akka.Remote.RemoteActorRefProvider, Akka.Remote"
}
remote {
helios.tcp {
port = 9870 #bound to a specific port
hostname = localhost
}
}
persistence {
publish-plugin-commands = on
journal {
#plugin = "akka.persistence.journal.sqlite"
plugin = "akka.persistence.journal.mongodb"
mongodb {
class = "Akka.Persistence.MongoDb.Journal.MongoDbJournal, Akka.Persistence.MongoDb"
connection-string = "mongodb://localhost/Akka"
collection = "EventJournal"
}
sqlite {
class = "Akka.Persistence.Sqlite.Journal.SqliteJournal, Akka.Persistence.Sqlite"
plugin-dispatcher = "akka.actor.default-dispatcher"
connection-string = "FullUri=file:Sqlite-journal.db?cache=shared;"
connection-timeout = 30s
schema-name = dbo
table-name = event_journal
auto-initialize = on
timestamp-provider = "Akka.Persistence.Sql.Common.Journal.DefaultTimestampProvider, Akka.Persistence.Sql.Common"
}
}
snapshot-store {
#plugin = "akka.persistence.snapshot-store.sqlite"
plugin = "akka.persistence.snapshot-store.mongodb"
mongodb {
class = "Akka.Persistence.MongoDb.Snapshot.MongoDbSnapshotStore, Akka.Persistence.MongoDb"
connection-string = "mongodb://localhost/Akka"
collection = "SnapshotStore"
}
sqlite {
class = "Akka.Persistence.Sqlite.Snapshot.SqliteSnapshotStore, Akka.Persistence.Sqlite"
plugin-dispatcher = "akka.actor.default-dispatcher"
connection-string = "FullUri=file:Sqlite-journal.db?cache=shared;"
connection-timeout = 30s
schema-name = dbo
table-name = snapshot_store
auto-initialize = on
}
}
}
}
]]>
</hocon>
So, back to my original question: Is there are working MongoDb sample that I can examine to learn how this is intended to work?
Configuration requires providing fully qualified type names with assemblies. Try to specify class as "Akka.Persistence.MongoDb.Journal.MongoDbJournal, Akka.Persistence.MongoDb" (you probably don't need double quotes either, as it's not inline string).
An old thread, but here's a large sample I put together years ago using Akka.Persistence.MongoDb + Clustering: https://github.com/Aaronontheweb/InMemoryCQRSReplication

Meteor 0.6.4.1 changes confuses coffeescript?

After upgrading from Meteor 0.5.4 to Meteor 0.6.4.1 I modified my coffeescript code accordingly to reflect changes of the variable scope. For some reason I think the changes confused the coffeescript to javascript interpretation?
Current code:
#liveObjects = {}
test = () ->
if liveObjects.intervalID?
donothing;
liveObjects = {} --Maybe this is what caused the confusion? Mistaken as a local variable declaration?
From the Chrome tool I noticed that the javascript code as
(function() { var test;
this.liveObjects = {};
test = function() {
var liveObjects;
if (liveObjects.intervalID != null) { --ReferenceError: liveObjects is not defined
donothing;
}
liveOjects = {};
You have to set it using this/# again.
#liveObjects = {}
test = () ->
if liveObjects.intervalID?
donothing;
#liveObjects = {}