MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / column_to_value

Function column_to_value

aiscript-vm/src/stdlib/db/sqlite.rs:36–89  ·  view source on GitHub ↗
(
    ctx: Context<'gc>,
    row: &sqlx::sqlite::SqliteRow,
    i: usize,
    type_info: &sqlx::sqlite::SqliteTypeInfo,
)

Source from the content-addressed store, hash-verified

34}
35
36fn column_to_value<'gc>(
37 ctx: Context<'gc>,
38 row: &sqlx::sqlite::SqliteRow,
39 i: usize,
40 type_info: &sqlx::sqlite::SqliteTypeInfo,
41) -> Result<Value<'gc>, VmError> {
42 // Handle NULL values first
43 if row.try_get_raw(i).map_or(true, |v| v.is_null()) {
44 return Ok(Value::Nil);
45 }
46
47 let value = match type_info.name() {
48 // Integer types
49 "INTEGER" => row.try_get::<i64, _>(i).map(|v| Value::Number(v as f64)),
50
51 // Floating-point types
52 "REAL" => row.try_get::<f64, _>(i).map(Value::Number),
53
54 // Text types
55 "TEXT" => row
56 .try_get::<String, _>(i)
57 .map(|v| Value::String(ctx.intern(v.as_bytes()))),
58
59 // Boolean type (stored as INTEGER in SQLite)
60 "BOOLEAN" => row.try_get::<bool, _>(i).map(Value::Boolean),
61
62 // Date/Time types (stored as TEXT or INTEGER in SQLite)
63 "DATETIME" => row
64 .try_get::<sqlx::types::chrono::NaiveDateTime, _>(i)
65 .map(|v| Value::String(ctx.intern(v.to_string().as_bytes()))),
66
67 // BLOB type
68 "BLOB" => row
69 .try_get::<Vec<u8>, _>(i)
70 .map(|v| Value::String(ctx.intern(&v))),
71
72 // JSON type (stored as TEXT in SQLite)
73 "JSON" => row
74 .try_get::<serde_json::Value, _>(i)
75 .map(|v| Value::String(ctx.intern(v.to_string().as_bytes()))),
76
77 // Default to string for unknown types
78 _ => row
79 .try_get::<String, _>(i)
80 .map(|v| Value::String(ctx.intern(v.as_bytes()))),
81 }
82 .unwrap_or_else(|_| {
83 // If conversion fails, try to get as string
84 row.try_get::<String, _>(i)
85 .map(|v| Value::String(ctx.intern(v.as_bytes())))
86 .unwrap_or(Value::Nil)
87 });
88 Ok(value)
89}
90
91fn row_to_object<'gc>(ctx: Context<'gc>, row: &sqlx::sqlite::SqliteRow) -> Value<'gc> {
92 let mut obj = Object::default();

Callers 2

row_to_objectFunction · 0.70
execute_typed_queryFunction · 0.70

Calls 3

as_bytesMethod · 0.80
nameMethod · 0.45
internMethod · 0.45

Tested by

no test coverage detected