[Module] JSON Datenbank(All OS)

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
Benutzeravatar
Thorsten1867
Beiträge: 1359
Registriert: 04.02.2005 15:40
Computerausstattung: [Windows 10 x64] [PB V5.7x]
Wohnort: Kaufbeuren
Kontaktdaten:

[Module] JSON Datenbank(All OS)

Beitrag von Thorsten1867 »

JSON Datenbank - Module (All OS / DPI)

Für ein Projekt benötige ich eine Datenbank, die ich direkt aus dem Speicher in ein Archiv packen bzw. verschlüsseln kann, ohne den Umweg über die Festplatte nehmen zu müssen. JSON scheint mir dafür der geeignete Weg zu sein.

- einfacheres Handling im Vergleich zu SQL
- Syntax für Abfragen soweit nötig an SQL angelehnt
- Abfragen können direkt in eine Linked List kopiert werden (#CopyToList)
- direktes Soeichern und Laden in bzw. aus ein(em) Archiv möglich
- AES-Verschlüsselung unterstützt
- Unterstützte Datentypen: String, Integer, Quad, Float, Double, Boolean und Blob
- Laden bzw. speichern von Blobs (z.B. Bilder) direkt aus bzw. in eine(r) Datei

Code: Alles auswählen

; jDB::Create()          - Create a new database
; jDB::Open()            - Open a database file
; jDB::Save()            - Save database as file
; jDB::AddPack()         - Save database in an archive
; jDB::UncompressPack()  - Load database from an archive
; jDB::Close()           - Close database
;
; jDB::Create()          - Create a new database
; jDB::AddTable()        - Add a database table
; jDB::AddColumn()       - Add a table column
; jDB::AddDataset()      - Add new database row with column data
; 
; jDB::Drop()            - Delete database table
; jDB::Table()           - Select a table
;
; jDB::AffectedRows()    - Number of database rows affected or selected
; jDB::ColumnType()      - Returns the type of the column (#String/#Integer/#Quad/#Float/#Double/#Blob)
; jDB::CheckNull()       - Returns #True if column = literal zero
;
; jDB::SelectRow()       - Select a row with its ID
; jDB::Query()           - Select several rows by means of an expression
; jDB::FinishQuery()     - Resets the selection and releases the resources
; jDB::Update()          - Update selected row(s) by means of an expression
; jDB::FinishUpdate()    - Resets the selection and releases the resources
; jDB::Combine()         - Combine two tables
; jDB::FinishCombine()   - Resets the selection and and removes the temporary table
; jDB::Join()            - Combine two tables and create a new table
;
; jDB::Delete()          - Delete selected row(s) by means of an expressio
; jDB::Sort()            - Change the order of the selected rows
;
; jDB::FirstRow          - Go to the first selected row
; jDB::PreviousRow()     - Go to the previous selected row
; jDB::NextRow()         - Go to the next selected row
; jDB::LastRow()         - Go to the last selected row
; jDB::ResetRows()       - Go before the first row to process all rows with NextRow()
;
; jDB::GetBoolean()      - Get the content of the column from the current row (Boolean)
; jDB::GetInteger()      - Get the content of the column from the current row (Integer)
; jDB::GetQuad()         - Get the content of the column from the current row (Quad)
; jDB::GetFloat()        - Get the content of the column from the current row (Float)
; jDB::GetDouble()       - Get the content of the column from the current row (Double)
; jDB::GetString()       - Get the content of the column from the current row (String)
;
; jDB::UpdateDataset()   - Change the value of all column from the current row
;
; jDB::SetBoolean()      - Change the value of the column from the current row (Boolean)
; jDB::SetInteger()      - Change the value of the column from the current row (Integer)
; jDB::SetQuad()         - Change the value of the column from the current row (Quad)
; jDB::SetFloat()        - Change the value of the column from the current row (Float)
; jDB::SetDouble()       - Change the value of the column from the current row (Double)
; jDB::SetString()       - Change the value of the column from the current row (String)
;
; jDB::GetBlob()         - Loads the blob into the memory
; jDB::BlobSize()        - Returns the size of the blob for allocating the memory 
; jDB::SaveBlob()        - Saves the blob as a file
;
; jDB::SetBlob()         - Saves the memory as a blob in the column
; jDB::LoadBlob()        - Saves the file as a blob in the column

; jDB::FileToBlob()      - Returns file as blob string for the use with DataSet()
; jDB::MemoryToBlob()    - Returns memory as blob string for the use with DataSet()

Download: JsonDatabaseModule.pbi
Download of PureBasic - Module
Download of PureBasic - Programmes

[Windows 11 x64] [PB V6]

Bild
Benutzeravatar
jacdelad
Beiträge: 341
Registriert: 03.02.2021 13:39
Computerausstattung: Ryzen 5800X, 108TB Festplatte, 32GB RAM, Radeon 7770OC
Wohnort: Riesa
Kontaktdaten:

Re: [Module] JSON Datenbank(All OS)

Beitrag von jacdelad »

Sehr cool, genau was ich brauche. Vielen Dank!
Ich kann es erst später testen: Ist die Komprimierung automatisch? So in etwa wie bei "Save" einen Parameter angeben, damit die Datenbank gepackt wird? Oder muss ich den Umweg über UncompressPack und AddPack gehen?
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Benutzeravatar
Thorsten1867
Beiträge: 1359
Registriert: 04.02.2005 15:40
Computerausstattung: [Windows 10 x64] [PB V5.7x]
Wohnort: Kaufbeuren
Kontaktdaten:

Re: [Module] JSON Datenbank(All OS)

Beitrag von Thorsten1867 »

Du kannst diese in jedes beliebige Archiv packen, wenn du dessen ID hast.

Code: Alles auswählen

If jDB::Create(#DB, "Test") 
        
  jDB::AddTable(#DB, "Table")
        
  jDB::AddColumn(#DB, "Name",   jDB::#String)
  jDB::AddColumn(#DB, "Gender", jDB::#String)
  jDB::AddColumn(#DB, "Age",    jDB::#Integer)
        
  jDB::AddDataset(#DB, "Peter|m|18", "Row1")
  jDB::AddDataset(#DB, "Sarah|f|24", "Row2")
  jDB::AddDataset(#DB, "James|m|67", "Row3")
  jDB::AddDataset(#DB, "Megan|f|14", "Row4")
        
  If CreatePack(#Pack, "Test.zip") 
          
    jDB::AddPack(#DB, #Pack, "Test.dbj")  ; <===
        
    ClosePack(#Pack) 
  EndIf
        
  jDB::Close(#DB)
EndIf
Download of PureBasic - Module
Download of PureBasic - Programmes

[Windows 11 x64] [PB V6]

Bild
Benutzeravatar
Kiffi
Beiträge: 10620
Registriert: 08.09.2004 08:21
Wohnort: Amphibios 9

Re: [Module] JSON Datenbank(All OS)

Beitrag von Kiffi »

:allright:
Hygge
Benutzeravatar
Thorsten1867
Beiträge: 1359
Registriert: 04.02.2005 15:40
Computerausstattung: [Windows 10 x64] [PB V5.7x]
Wohnort: Kaufbeuren
Kontaktdaten:

Re: [Module] JSON Datenbank(All OS)

Beitrag von Thorsten1867 »

Update: #Compressed für jDB::Save() & jDB::Open() hinzugefügt
Download of PureBasic - Module
Download of PureBasic - Programmes

[Windows 11 x64] [PB V6]

Bild
Benutzeravatar
jacdelad
Beiträge: 341
Registriert: 03.02.2021 13:39
Computerausstattung: Ryzen 5800X, 108TB Festplatte, 32GB RAM, Radeon 7770OC
Wohnort: Riesa
Kontaktdaten:

Re: [Module] JSON Datenbank(All OS)

Beitrag von jacdelad »

Ah danke. Ich hätte mir das sonst selbst gebastelt.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Antworten