Closed emakei closed 1 month ago
Odd, would you be kind enough to show me your code?
Oh. I see that if I use this variable in file (script) then SQL-statements logging to STDOUT. But I steel cant see any new rows in database. But when I run sql-statements from inside sqlite3 and change only "Bool::True" to 1 from Red output I see new row.
Models.rakumod:
use Red:api<2>;
use RedX::HashedPassword;
use UUID::V4;
model User { ... };
model Company is rw is export {
has Str $.id is column = uuid-v4();
has Str $.name is column is required;
has Str $.official-name is column = "";
has Str $.reg-number is column = "";
has Str $.official-addr is column = "";
has Str $.email-addr is column = "";
has Str $.main-addr is column = "";
has Str $.skype-nick is column = "";
has Str $.telegram-nick is column = "";
has Str $.phone-number is column = "";
has User @.users is relationship{ .company-id };
}
model User is rw is export {
has Str $.id is column = uuid-v4();
has Str $!company-id is referencing( *.id, :model(Company));
has Str $.login-name is column( :unique );
has Str $.password is password handles <check-password>;
has Bool $.is-admin is column = False;
has Str $.full-name is column = "";
has Str $.email-addr is column = "";
has Str $.skype-nick is column = "";
has Str $.telegram-nick is column = "";
has Str $.phone-number is column = "";
has Str $.home-addr is column = "";
has Company $.company is relationship{ .company-id };
}
test.raku:
use Red:api<2>;
use Models;
my $*RED-DEBUG = True;
red-defaults “SQLite”, database => 'test.sqlite3';
Company.^create-table;
my $company = Company.^create(name => 'abc');
for Company.^all -> $item { say $item };
User.^create-table;
my $admin = $company.users.create(login-name => 'admin', password => 'nimda', full-name => "Administrator", is-admin => True);
$company.users.create(login-name => "fox", password => "xof", full-name => "Jon");
for User.^all -> $item { say $item }
Hi! Sorry for the delay. Using your code (putting on a single file and removing the external dependency) I'm getting this error:
Is that what you are getting? (I'm on Rakudo™ v2024.09).
I'm trying to fix this problem.
Removing UUID::V4 the error stops...
I found it! on your code, Company's and User's id should be is id
instead of is
column`.
I'm trying to make it not break in that case. but is referencing
should always point to an id.
it also worked on moar-2024.07. I'll release a new version
and here is what's inside the db:
SQLite version 3.39.5 2022-10-14 20:58:05
Enter ".help" for usage hints.
sqlite> .d
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "company" (
id text NOT NULL ,
name text NOT NULL ,
official_name text NOT NULL ,
reg_number text NOT NULL ,
official_addr text NOT NULL ,
email_addr text NOT NULL ,
main_addr text NOT NULL ,
skype_nick text NOT NULL ,
telegram_nick text NOT NULL ,
phone_number text NOT NULL
);
INSERT INTO company VALUES('202e5dba-7cf7-42c1-b08c-31f4bf0c24cb','abc','','','','','','','','');
CREATE TABLE IF NOT EXISTS "user" (
id text NOT NULL ,
company_id text NULL references company(id),
login_name text NOT NULL ,
is_admin integer NOT NULL ,
full_name text NOT NULL ,
email_addr text NOT NULL ,
skype_nick text NOT NULL ,
telegram_nick text NOT NULL ,
phone_number text NOT NULL ,
home_addr text NOT NULL ,
UNIQUE (login_name)
);
INSERT INTO user VALUES('360e2e49-3e0b-48ca-966a-c3cdace767d6','202e5dba-7cf7-42c1-b08c-31f4bf0c24cb','admin',1,'Administrator','','','','','');
INSERT INTO user VALUES('cc467ae7-e554-4a0f-b007-0db8942a5229','202e5dba-7cf7-42c1-b08c-31f4bf0c24cb','fox',0,'Jon','','','','','');
COMMIT;
https://github.com/FCO/Red/commit/649f0e68eb89cee239338441a371a5b8163e5a3f
@emakei could you confirm that's working, please?
I use
red-defaults
and afterUser.^create(...)
and$company.users.create(...)
I see no new users and any errors. Then I set$*RED-DEBUG
toTrue
and see no output (SQL statements) for any action on my models (even for working code).