fix osis compilation
This commit is contained in:
@@ -1,11 +1,5 @@
|
|||||||
module osis
|
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 {
|
pub fn new(config OSISConfig) !OSIS {
|
||||||
return OSIS{
|
return OSIS{
|
||||||
indexer: new_indexer()!
|
indexer: new_indexer()!
|
||||||
|
|||||||
@@ -2,10 +2,8 @@ module osis
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import db.sqlite
|
import db.sqlite
|
||||||
import db.pg
|
|
||||||
import freeflowuniverse.herolib.core.texttools
|
import freeflowuniverse.herolib.core.texttools
|
||||||
import freeflowuniverse.herolib.core.pathlib
|
import freeflowuniverse.herolib.core.pathlib
|
||||||
import orm
|
|
||||||
|
|
||||||
pub struct Indexer {
|
pub struct Indexer {
|
||||||
db sqlite.DB
|
db sqlite.DB
|
||||||
@@ -27,10 +25,18 @@ pub fn reset(path string) ! {
|
|||||||
db_file.delete()!
|
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,
|
// 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
|
// and the table belonging to the type of root object with columns for index fields
|
||||||
pub fn (mut backend Indexer) new(object RootObject) !u32 {
|
pub fn (mut i Indexer) new(table string, id u32, indices map[string]string) !u32 {
|
||||||
panic('implement')
|
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
|
// 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
|
// get_table_name returns the name of the table belonging to a root struct
|
||||||
fn get_table_name(object RootObject) string {
|
fn get_table_name(object RootObject) string {
|
||||||
panic('implement')
|
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
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,5 @@
|
|||||||
module osis
|
module osis
|
||||||
|
|
||||||
import os
|
|
||||||
import db.sqlite
|
|
||||||
import db.pg
|
|
||||||
import freeflowuniverse.herolib.data.dbfs
|
|
||||||
import freeflowuniverse.herolib.data.encoderhero
|
|
||||||
|
|
||||||
pub struct OSIS {
|
pub struct OSIS {
|
||||||
pub mut:
|
pub mut:
|
||||||
indexer Indexer // storing indeces
|
indexer Indexer // storing indeces
|
||||||
@@ -19,4 +13,4 @@ pub:
|
|||||||
name string
|
name string
|
||||||
secret string
|
secret string
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,6 @@
|
|||||||
module osis
|
module osis
|
||||||
|
|
||||||
import os
|
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 {
|
pub fn (mut o OSIS) generic_new[T](obj T) !u32 {
|
||||||
id := o.indexer.generic_new[T](obj)!
|
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 {
|
pub fn (mut o OSIS) new[T](obj T) !u32 {
|
||||||
id := o.indexer.generic_new[T](obj)!
|
id := o.storer.new_generic[T](obj)!
|
||||||
o.storer.generic_new[T](obj)!
|
o.indexer.new_generic[T](id, obj)!
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,7 +18,7 @@ pub fn (mut o OSIS) generic_get[T](id u32) !T {
|
|||||||
return o.storer.generic_get[T](id)!
|
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))!
|
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)!
|
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))!
|
o.storer.delete(u32(id))!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import json
|
|||||||
|
|
||||||
// new creates a new root object entry in the root_objects table,
|
// 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
|
// 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()
|
data := json.encode(obj).bytes()
|
||||||
return storer.db.set(data: data)
|
return storer.db.set(data: data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ import os
|
|||||||
// and maintains a linked list of previous values for history tracking
|
// 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)
|
// Returns the ID used (either x if specified, or auto-incremented if x=0)
|
||||||
@[params]
|
@[params]
|
||||||
struct OurDBSetArgs {
|
pub struct OurDBSetArgs {
|
||||||
|
pub:
|
||||||
id ?u32
|
id ?u32
|
||||||
data []u8 @[required]
|
data []u8 @[required]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user