Database seeder lazarus / 16-Databases ---------------------------------------------------------------------- tudi_x · 2018-03-17 10:27 hi, would you know if some database seeder code / classes would exist for Pascal? (https://en.wikipedia.org/wiki/Database_seeding) thank you ---------------------------------------------------------------------- JD · 2018-03-17 13:03 DBeaver 5.0 https://dbeaver.jkiss.org/ can generate mock data for tables JD ---------------------------------------------------------------------- rvk · 2018-03-17 13:49 Quote from: tudi_x on March 17, 2018, 11:27:08 amwould you know if some database seeder code / classes would exist for Pascal? Are you talking about mock data ??? The option in DBeaver is indeed nice but the data really doesn't mean anything. You could just generate a random string yourself. I have a test-project that downloads real "mock" data from https://randomuser.me. It's not finished yet and the downloading and creating of the database could be moved to a separate class but it already works quite nice. (attached) It is self-contained. It will download openssl (if needed) for Windows so if you're not on Windows you might need to strip that function- call. Furthermore it will download test-data (200 persons, with picture url) and read it in a new database SQLite3 (you do need to add the dll yourself at the moment). ---------------------------------------------------------------------- JD · 2018-03-17 14:09 Quote from: rvk on March 17, 2018, 02:49:16 pmQuote from: tudi_x on March 17, 2018, 11:27:08 amwould you know if some database seeder code / classes would exist for Pascal? Are you talking about mock data ??? The option in DBeaver is indeed nice but the data really doesn't mean anything. You could just generate a random string yourself. I have a test-project that downloads real "mock" data from https://randomuser.me. It's not finished yet and the downloading and creating of the database could be moved to a separate class but it already works quite nice. (attached) It is self-contained. It will download openssl (if needed) for Windows so if you're not on Windows you might need to strip that function- call. Furthermore it will download test-data (200 persons, with picture url) and read it in a new database SQLite3 (you do need to add the dll yourself at the moment). Thanks for the link and your example project rvk. I did not know about that one & furthermore the data format is quite flexible.  JD ---------------------------------------------------------------------- tudi_x · 2018-03-17 14:26 thank you guys! i will adopt the SSL download approach for future. basically based on a data definition in first part of JSON, a thread would create table if it does not exist. second part of JSON could be the data to seed. same data, same table would be consistent for DevOps. ---------------------------------------------------------------------- taazz · 2018-03-17 14:52 Quote from: tudi_x on March 17, 2018, 03:26:27 pmthank you guys! i will adopt the SSL download approach for future. basically based on a data definition in first part of JSON, a thread would create table if it does not exist. second part of JSON could be the data to seed. same data, same table would be consistent for DevOps. that is called a DDL file, In short you write a text file that has all the commands to create the tables and insert their data why do you need a json file ? If you do need a json have checked the database import package that comes with lazarus for a control that can import json data? ---------------------------------------------------------------------- tudi_x · 2018-03-17 17:16 i need a JSON in order to be able to send the commands on a REST Endpoint to the app that resides in a container. i searched for the database import with no luck. could you please point me in the right direction or a wiki entry? thank you ---------------------------------------------------------------------- taazz · 2018-03-17 17:39 Quote from: tudi_x on March 17, 2018, 06:16:43 pmi need a JSON in order to be able to send the commands on a REST Endpoint to the app that resides in a container. so send a json with the sql command as a value to a property/field. I hypothesize that it will be  around 20% smaller. Quote from: tudi_x on March 17, 2018, 06:16:43 pmi searched for the database import with no luck. could you please point me in the right direction or a wiki entry? thank you seems that my memory failed me I was referring to http://wiki.freepascal.org/lazdbexport there is a link at the bottom https://bitbucket.org/reiniero/smalltools/src which will give you a starting point. ---------------------------------------------------------------------- tudi_x · 2018-03-17 17:55 do not want to send SQL creation commands as the structure might be coming from apps or users that are not aware of SQL. also the user would need to know what type of RDBMS is deployed which is too much sometimes (the app holding the REST would do the discovery solely). thank you for the link. ---------------------------------------------------------------------- JD · 2018-03-18 08:03 Quote from: tudi_x on March 17, 2018, 06:55:30 pmdo not want to tie to SQL as the structure might be coming from apps or users that are not aware of SQL. also the user would need to know what type of RDBMS is deployed which is too much sometimes (the app holding the REST would do the discovery solely). thank you for the link. I send JSON data to databases (Firebird and PostgreSQL) behind a remote REST server that I built using Lazarus. The REST server uses SQLdb to convert the data into SQL parameters for predefined INSERT, UPDATE, DELETE statements. I then call SQLDb's ExecSQL to post the data into the databases. That is the beauty of having an application server. It does the work and the user/client app does not need to know anything about how the data is processed by the server. If you don't like that method, you can send JSON data directly to a stored procedure in the database. The stored procedure will parse the JSON data and update the database accordingly. Another option, if you are using PostgreSQL or MariaDB, is to use their JSON functionalities to parse the sent data and update the database. Cheers, JD