fix osis compilation

This commit is contained in:
timurgordon
2025-01-21 02:37:05 +00:00
parent dfeeb8cd4c
commit d403f84b6c
6 changed files with 35 additions and 27 deletions

View File

@@ -1,11 +1,5 @@
module osis
import os
import db.sqlite
import db.pg
import freeflowuniverse.herolib.data.dbfs
import freeflowuniverse.herolib.data.encoderhero
pub fn new(config OSISConfig) !OSIS {
return OSIS{
indexer: new_indexer()!

View File

@@ -2,10 +2,8 @@ module osis
import json
import db.sqlite
import db.pg
import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.core.pathlib
import orm
pub struct Indexer {
db sqlite.DB
@@ -27,10 +25,18 @@ pub fn reset(path string) ! {
db_file.delete()!
}
pub fn (mut i Indexer) new_generic[T](id u32, object T) !u32 {
return i.new(get_table[T](), id, get_indices[T](object))!
}
// new creates a new root object entry in the root_objects table,
// and the table belonging to the type of root object with columns for index fields
pub fn (mut backend Indexer) new(object RootObject) !u32 {
panic('implement')
pub fn (mut i Indexer) new(table string, id u32, indices map[string]string) !u32 {
insert_query := 'INSERT into ${table} (${indices.keys().join(',')}) values (${indices.values().join(',')})'
i.db.exec(insert_query) or {
return error('Error inserting object ${id} into table ${table}\n${err}')
}
return 0
}
// save the session to redis & mem
@@ -90,4 +96,21 @@ fn (mut backend Indexer) table_exists(table_name string) !bool {
// get_table_name returns the name of the table belonging to a root struct
fn get_table_name(object RootObject) string {
panic('implement')
}
// get_table_name returns the name of the table belonging to a root struct
fn get_table[T]() string {
return typeof[T]()
}
// returns the lists of the indices of a root objects db table, and corresponding values
pub fn get_indices[T](object T) map[string]string {
mut indices := map[string]string
$for field in T.fields {
if field.attrs.contains('index') {
value := object.$(field.name)
indices[field.name] = '${value}'
}
}
return indices
}

View File

@@ -1,11 +1,5 @@
module osis
import os
import db.sqlite
import db.pg
import freeflowuniverse.herolib.data.dbfs
import freeflowuniverse.herolib.data.encoderhero
pub struct OSIS {
pub mut:
indexer Indexer // storing indeces
@@ -19,4 +13,4 @@ pub:
name string
secret string
reset bool
}
}

View File

@@ -1,10 +1,6 @@
module osis
import os
import db.sqlite
import db.pg
import freeflowuniverse.herolib.data.dbfs
import freeflowuniverse.herolib.data.encoderhero
pub fn (mut o OSIS) generic_new[T](obj T) !u32 {
id := o.indexer.generic_new[T](obj)!
@@ -13,8 +9,8 @@ pub fn (mut o OSIS) generic_new[T](obj T) !u32 {
}
pub fn (mut o OSIS) new[T](obj T) !u32 {
id := o.indexer.generic_new[T](obj)!
o.storer.generic_new[T](obj)!
id := o.storer.new_generic[T](obj)!
o.indexer.new_generic[T](id, obj)!
return id
}
@@ -22,7 +18,7 @@ pub fn (mut o OSIS) generic_get[T](id u32) !T {
return o.storer.generic_get[T](id)!
}
pub fn (mut o OSIS) get[T](id int) !T {
pub fn (mut o OSIS) get[T](id u32) !T {
return o.storer.generic_get[T](u32(id))!
}
@@ -36,7 +32,7 @@ pub fn (mut o OSIS) generic_delete[T](id u32) ! {
o.storer.generic_delete[T](id)!
}
pub fn (mut o OSIS) delete(id int) ! {
pub fn (mut o OSIS) delete(id u32) ! {
o.storer.delete(u32(id))!
}

View File

@@ -4,7 +4,7 @@ import json
// new creates a new root object entry in the root_objects table,
// and the table belonging to the type of root object with columns for index fields
pub fn (mut storer Storer) generic_new[T](obj T) !u32 {
pub fn (mut storer Storer) new_generic[T](obj T) !u32 {
data := json.encode(obj).bytes()
return storer.db.set(data: data)
}

View File

@@ -18,7 +18,8 @@ import os
// and maintains a linked list of previous values for history tracking
// Returns the ID used (either x if specified, or auto-incremented if x=0)
@[params]
struct OurDBSetArgs {
pub struct OurDBSetArgs {
pub:
id ?u32
data []u8 @[required]
}