You are not logged in.
Pages: 1
And in the methods work with DB like MVC demo?
Dear ab Im waiting for your answer what ever it is.
OK.I read the chapter and check demos 14,16 and 30 again.But I understand that I should use interfaces in server and client like calculator example but in MVC demo just right class,why is that?
I changes structure like this but is it right?
unit NoteInterface;
interface
uses
SysUtils,
SynCommons,
SynCrypto,
mORMot;
type
TSQLRecordTimeStamped = class(TSQLRecord)
private
fCreatedAt: TCreateTime;
fModifiedAt: TModTime;
published
property CreatedAt: TCreateTime read fCreatedAt write fCreatedAt;
property ModifiedAt: TModTime read fModifiedAt write fModifiedAt;
end;
TSQLSomeone = class(TSQLRecordTimeStamped)
private
fFirstName: RawUTF8;
fFamilyName: RawUTF8;
fEmail: RawUTF8;
fHashedPassword: RawUTF8;
fLogonName: RawUTF8;
public
procedure SetPlainPassword(const PlainPassword: RawUTF8);
function CheckPlainPassword(const PlainPassword: RawUTF8): boolean;
function Name: RawUTF8;
published
property LogonName: RawUTF8 index 30 read fLogonName write fLogonName stored AS_UNIQUE;
property FirstName: RawUTF8 index 50 read fFirstName write fFirstName;
property FamilyName: RawUTF8 index 50 read fFamilyName write fFamilyName;
property Email: RawUTF8 index 40 read fEmail write fEmail;
property HashedPassword: RawUTF8 index 64 read fHashedPassword write fHashedPassword;
end;
TSQLUser = class(TSQLSomeone)
private
public
class procedure InitializeTable(Server: TSQLRestServer; const FieldName: RawUTF8;
Options: TSQLInitializeTableOptions); override;
end;
TSQLContent = class(TSQLRecordTimeStamped)
private
fContent: RawUTF8;
fTitle: RawUTF8;
fUser: TSQLUser;
published
property Title: RawUTF8 index 120 read fTitle write fTitle;
property Content: RawUTF8 read fContent write fContent;
property User: TSQLUser read fUser write fUser;
end;
TSQLNote = class(TSQLContent)
private
public
class procedure InitializeTable(Server: TSQLRestServer; const FieldName: RawUTF8;
Options: TSQLInitializeTableOptions); override;
end;
INoteManager = interface(IInvokable)
['{539876CF-E719-4129-A359-2916A99F8FA3}']
function LogIn(const Username:RawUTF8; const Password:RawUTF8):Boolean;
function LogOut:Boolean;
function Add(const Text:RawUTF8;Out Note:TSQLNote):Boolean;
function Delete(const Note:TSQLNote):Boolean;
function Update(var Note:TSQLNote;Text:RawUTF8):Boolean;
end;
const
ROOT_NAME = 'root';
PORT_NAME = '888';
APPLICATION_NAME = 'NoteManager';
function CreateModel: TSQLModel;
implementation
const
SALT = 'JustANoteManager';
function CreateModel: TSQLModel;
begin
result := TSQLModel.Create([TSQLNote,TSQLUser],'note');
end;
function TSQLSomeone.CheckPlainPassword(const PlainPassword: RawUTF8): boolean;
begin
result := fHashedPassword=SHA256(SALT+LogonName+PlainPassword);
end;
function TSQLSomeone.Name: RawUTF8;
begin
result := FirstName+' '+FamilyName;
end;
procedure TSQLSomeone.SetPlainPassword(const PlainPassword: RawUTF8);
begin
fHashedPassword := SHA256(SALT+LogonName+PlainPassword);
end;
{ TSQLUser }
class procedure TSQLUser.InitializeTable(Server: TSQLRestServer;
const FieldName: RawUTF8; Options: TSQLInitializeTableOptions);
begin
inherited;
end;
{ TSQLNote }
class procedure TSQLNote.InitializeTable(Server: TSQLRestServer;
const FieldName: RawUTF8; Options: TSQLInitializeTableOptions);
begin
inherited;
end;
end.
I went for reading it when you said and its abot to finish.Then I will update test project and post here.
I should say my imagination is like this in PHP mode:
-We have some MySQL procedures like login,add,search and ... that do what they should.
-We make some php procedures like before that call Mysql procedures and control error and return result as JSON and I could go to api.example.com/notemanager/notes?ID=1&key=piqmsbzctyonvmascus (key is a client key for auth) and get note with ID=1 as JSON.
-We work with JSON in Delphi,FPC or Android app and done.
In mORMot I understand that:
-I should make an interface for server that have all the functions and give results back as out variant so can take care of memory.
-I should implement interface as a class and use it in client.
-It sound easy but there is many many items that talked about in doc that I dont know how and when to use them,Also how can I get JSON from a browser for just looking at it or use it in for example in Android(as I dont know enough to use or make a mORMot implementation in java so use it old school way,pars and use).
If I can make it work I will make this project clean and it can help me others to have a walkthrough for mORMot.
1-Ok I get it.
Its a simple note manager,User write text and add it and I want to get back TNote that contain note info like time stamp,Id and others.
3-How?I read ORM parts but every way I think I need to write a sql code for getting for example note info or adding it into database.
4-As I said I want to make a test project and in this way learn how work with mORMot and the subject is a simple note manager.
ab is it OK Im asking these newbie question here? I dont want to spam here but as you saw I stuck
Hi,
I read to from beginning to end of chapter 17.
I learned about mORmot and its great system and about SOA but still I cant find out how make my service,I tried my best but its hard for me,in PHP its easy but in mORmot I still cant understand it enough.
So I decided to make a test project until it be the best.
Test project is a simple note manager server with MySQL DB and should have an simple API,user can login,add,update,delete and logout,Just it.
I made what I learned (I learned more but its not useful for making project),Here it is and I know its so less.
unit NoteInterface;
interface
uses mORMot;
type
TNote=record
ID:Integer;
Text:RawUTF8;
Timestamp:TDateTime;
end;
INoteManagaer = interface(IInvokable)
['{539876CF-E719-4129-A359-2916A99F8FA3}']
function LogIn(Username,Password:RawUTF8):Boolean;
function LogOut:Boolean;
function Add(Text:RawUTF8;Out Note:TNote):Boolean;
function Delete(Note:TNote):Boolean;
function Update(var Note:TNote;Text:RawUTF8):Boolean;
end;
const
ROOT_NAME = 'root';
PORT_NAME = '888';
APPLICATION_NAME = 'NoteManager';
implementation
end.
program NoteTest;
{$APPTYPE CONSOLE}
uses
SysUtils,
NoteInterface in 'NoteInterface.pas';
type
TServiceCalculator = class(TInterfacedObject, INoteManagaer)
public
function LogIn(Username,Password:RawUTF8):Boolean;
function LogOut:Boolean;
function Add(Text:RawUTF8;Out Note:TNote):Boolean;
function Delete(Note:TNote):Boolean;
function Update(var Note:TNote;Text:RawUTF8):Boolean;
end;
{ TServiceCalculator }
function TServiceCalculator.Add(Text: RawUTF8; out Note: TNote): Boolean;
begin
//?
end;
function TServiceCalculator.Delete(Note: TNote): Boolean;
begin
//?
end;
function TServiceCalculator.LogIn(Username, Password: RawUTF8): Boolean;
begin
//?
end;
function TServiceCalculator.LogOut: Boolean;
begin
//?
end;
function TServiceCalculator.Update(var Note: TNote;
Text: RawUTF8): Boolean;
begin
//?
end;
var
aModel: TSQLModel;
aServer: TSQLRestServer;
aHTTPServer: TSQLHttpServer;
begin
aModel := TSQLModel.Create([],ROOT_NAME);
try
aServer := TSQLRestServerFullMemory.Create(aModel,'test.json',false,true);//?
try
aServer.ServiceRegister(TServiceCalculator,[TypeInfo(INoteManagaer)],sicShared);
aHTTPServer := TSQLHttpServer.Create(PORT_NAME,[aServer],'+',useHttpApiRegisteringURI);
try
writeln(#10'Press [Enter] to close the server.'#10);
readln;
finally
aHTTPServer.Free;
end;
finally
aServer.Free;
end;
finally
aModel.Free;
end;
end.
Now I dont know these things:
1-Is it my interface structure even right?
2-How can I make server for using it from a Delphi apps and a web browser?).
3-Should I right exact SQL code in functions like "insert into notetable values(:Text)" with TSQLDBConnectionProperties?
4-Im sure my server setting is wrong but in a lot of class and their options Im lost.
PS,Yes I read demos like CrossPlatform Clients but no I didnt get them right and yes maybe Im slow but Im triying for two week to learn and I need help.I always learn from examples and mORmot's examples are not a begin to end example and make it more complicated for me and about main demo its too complicated for a starter like me.
Thank you,I'm reading now.
It feels I'm in school again (feeling good)
Also I want to ask again is there a way to choose stored procedure for insert ,delete or add like libraries for example UniDac?
So when we call delete class call DeleteUser with needed parameters procedure and not delete from usertable where Id=n ?
So in this way I should for example SignUp user do all checking in FPC or Delphi and JAVA?
Write all code again for any new language?For that we made stored procedure in DB so we have procedure that get parameters and do all stuff and return result so we can use API from every where.
So ab please help me to understand what is the best way for such a thing? You now mORMot more that any one and I explained project for you and now I will explain more
Project is a simple and fast note synchronizer that we want to make it for free for our selves and other people specially developers.
Windows,Web,Android and iOS clients.they are in any languages just PC versions will be in FPC and maybe Website.
Also in the future we want to publish API for other developers to work with service.
How can I do it with mORMot in best way?
Hi ab and Thank you,
Its not distributing but its mind shaking
I read from first to chapter 14 until now, About iOS and Android I now mORMot support them but my team use AndroidStudio and java for android programing for example.For this I need JSON API like other services API.Or there is other way that I dont know?
About access to the server,its tempting what you say but one of my biggest problem is Im not alone just with FPC,project have Java Android client,iOS client and a FPC client,also maybe we have a web client so this way that client do all things and error messages and other stuffs is confusing for me also what if I want to release API for others?
Like you I dont like writing stored procedure in MySQL for many reason like speed and debugging but its not easy to understand.
I should say project is simple but its priority is multi platforming but I want to done all server stuff with FPC not PHP or python.
Also I want to ask is there a way to choose stored procedure for insert ,delete or add like libraries for example UniDac?
So when we call delete class call DeleteUser with needed parameters procedure and not delete from usertable where Id=n ?
After a while I came back to mORMot and I'm reading documentation.
In chapter 13 it talks about stored procedure but I cant understand.
I made a project before with this structure:
A server with MySQL and stored procedures for signup,sign in,getting list of users,getting list of users notes,search by user and subject and many others that are not a simple SQL.For these jobs I made stored procedures and in them I check validation of user ID or anything else and it will resturn result list and for jobs like signup it give some user info and session info and if there is error it add error to a variable and return result false so in php API it give last error and all result and errors will convert to JSON with php.
In client I work with API just like many other services with JSON API.
Also beside of Lazarus PC client I have Android and iOS version and I cant use mORMot in them and they will work with JSON.
So I want to make a new project like that one and for this one I want to remove php and do all works with FPC and mORMot and feel proud
I think I cant remove stored procedures because I cant let client do SQL jobs.
So can any one help me what is the best structure for doing this with mORMot?
I try to change project target but it says :
Compiler "/home/pp/development/fpc/bin/x86_64-linux/fpc.sh" does not support target i386-linux
In this answer author of fpcup said we cant compile 32bit in a 64bit Linux(it what I understand,maybe wrong).
http://forum.lazarus.freepascal.org/ind … #msg153422
I should say I install DPC with fpcup_linux_x64,Should I reinstall with 86 version?
I know my question is too newbie but I never play with this options and I'm always developing for windows.
I don't know how to do it really,In the past time I try but just with CodeTyphone I code do this.Can you help me?
And I get last version of mORMot and error change to SynCrypto :
SynCrypto.pas(1541,6) Error: Identifier not found "cfSSE41"
{$ifdef CPU64}
if cfSSE41 in CpuFeatures then begin
Exclude(CpuFeatures,cfSSE41);
result := result and SingleTest('abc', D1) and
SingleTest('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', D2);
Include(CpuFeatures,cfSSE41);
end
{$endif}
Yes my Xubuntu is 64 and I get it with fpcup.
Honestly until this time I didn't use fpcup and I don't know How to compile Laz and FPC 32 in a 64 linux.
How can I remove this one and compile a 32bit version?
OS:Xubunto 14.10
Lazarus : 1.5 2015-02-22
FPC : 3.1.1
I download all three 2 days ago and :
mORMot Nightly build 2015-02-20_160052_6eeb81a028
And I don't change anything in the sources,just make new project and copy documentation sample code and compile and error.
So I'm stuck
First I should thank you for this BIG documention.
Second I should thank you for "25.4.4. Linux installation tips" section,It helps me a lot.
Now problem:
I get Lazarus and FPC with fpcup and make new simple project like this :
program project1;
{$I Synopse.inc}
{$APPTYPE CONSOLE}
uses {$ifdef Linux} cthreads, cwstring, {$endif} mORMotSelfTests;
begin
SQLite3ConsoleTests;
end.
but in SynZip unit there is an error:
SynZip.pas(582,87) Error: Incompatible types: got "QWord" expected "LongWord"
Why?
Thank you ab.
I'm going to work with them and ask future question after I will stuck
Hi,
First apologies because of these too newbie questions,But I'm newbie with mORMot and web applications but familiar with Lazarus.
So questions:
1-I want to make a simple JSON API for my server and searching for a good library and I stuck in deciding with library is good for this situation;mORMot,Brook,Fast ... . And I know mORMot from 2 years ago ( but with a different name) and I never test it for a real job but it is very interesting and seems powerful but complicated to me but I like to use it.So is it mORMot good for a simple JSON API or I should choose another framework?
2-For this goal (simple JSON API) is there any example or a point to begin so I not be confused like now?
Thanks
Pages: 1