tosql_meta 0.1.2

Metadata definition for SQL struct serialization / SQL 结构体序列化的元数据定义
Documentation

English | 中文


tosql_meta : Metadata Definition for SQL Structs

Defines the Meta struct used to store type and field information for SQL serialization.

Table of Contents

Introduction

tosql_meta is a lightweight crate that provides the Meta struct. This struct is essential for the tosql ecosystem, as it holds the schema definition (field names and types) of a Rust struct. It is used by tosql_derive to generate metadata and by to_mysql to construct SQL statements.

Features

  • Simple Data Structure: Defines a clean Meta struct to hold schema information.
  • Serialization Support: Implements bitcode encoding and decoding for efficient metadata transfer.
  • Interoperability: Acts as the common schema definition shared across the tosql ecosystem.

Usage

This crate is primarily used internally by tosql and tosql_derive, but it can be used directly if you are building custom SQL generation tools.

Add it to your Cargo.toml:

[dependencies]
tosql_meta = "0.1"

Use it in your code:

use tosql_meta::Meta;
use kind2sql::Kind;

let meta = Meta {
    kind_li: vec![Kind::U64, Kind::String],
    field_li: vec!["id".to_string(), "name".to_string()],
};

println!("Fields: {:?}", meta.field_li);

API Reference

pub struct Meta

The core struct of this crate.

#[derive(bitcode::Encode, bitcode::Decode, PartialEq, Debug)]
pub struct Meta {
  pub kind_li: Vec<Kind>,
  pub field_li: Vec<String>,
}
  • kind_li: A vector of Kind enums representing the data types of the fields.
  • field_li: A vector of strings representing the names of the fields.

Tech Stack

  • Rust: The core programming language.
  • bitcode: Used for extremely fast binary serialization of the Meta struct.
  • kind2sql: Provides the Kind enum for type definitions.

Directory Structure

tosql_meta/
├── Cargo.toml      # Project configuration
├── readme/         # Documentation
│   ├── en.md       # English README
│   └── zh.md       # Chinese README
└── src/
    └── lib.rs      # Meta struct definition

Related Crates

History

The Origin of Metadata

The term "metadata" was coined in 1968 by Philip Baggett, but it wasn't until the 1990s that it became widely used in the tech industry. In the context of databases, metadata is "data about data"—it describes the structure, constraints, and types of the actual data stored in tables. Just as a library card catalog tells you where to find a book without being the book itself, tosql_meta tells the SQL generator how to interpret the binary data of your structs.


About

This project is an open-source component of js0.site ⋅ Refactoring the Internet Plan.

We are redefining the development paradigm of the Internet in a componentized way. Welcome to follow us:


tosql_meta : SQL 结构体元数据定义

定义了用于存储 SQL 序列化所需的类型和字段信息的 Meta 结构体。

目录

简介

tosql_meta 是一个轻量级库,提供了 Meta 结构体。该结构体在 tosql 生态系统中至关重要,因为它保存了 Rust 结构体的模式定义(字段名称和类型)。tosql_derive 使用它来生成元数据,to_mysql 使用它来构建 SQL 语句。

特性

  • 简洁的数据结构:定义了清晰的 Meta 结构体来保存模式信息。
  • 序列化支持:实现了 bitcode 编码和解码,以支持高效的元数据传输。
  • 互操作性:作为 tosql 生态系统中共享的通用模式定义。

使用方法

此库主要由 tosqltosql_derive 内部使用,但如果您正在构建自定义 SQL 生成工具,也可以直接使用它。

将其添加到您的 Cargo.toml

[dependencies]
tosql_meta = "0.1"

在代码中使用:

use tosql_meta::Meta;
use kind2sql::Kind;

let meta = Meta {
    kind_li: vec![Kind::U64, Kind::String],
    field_li: vec!["id".to_string(), "name".to_string()],
};

println!("字段: {:?}", meta.field_li);

API 参考

pub struct Meta

本库的核心结构体。

#[derive(bitcode::Encode, bitcode::Decode, PartialEq, Debug)]
pub struct Meta {
  pub kind_li: Vec<Kind>,
  pub field_li: Vec<String>,
}
  • kind_li:表示字段数据类型的 Kind 枚举向量。
  • field_li:表示字段名称的字符串向量。

技术栈

  • Rust:核心编程语言。
  • bitcode:用于 Meta 结构体的极速二进制序列化。
  • kind2sql:提供用于类型定义的 Kind 枚举。

目录结构

tosql_meta/
├── Cargo.toml      # 项目配置
├── readme/         # 文档
│   ├── en.md       # 英文 README
│   └── zh.md       # 中文 README
└── src/
    └── lib.rs      # Meta 结构体定义

相关库

历史

元数据的起源

“元数据”(Metadata)一词由 Philip Baggett 于 1968 年创造,但直到 20 世纪 90 年代才在科技行业广泛使用。在数据库语境下,元数据是“关于数据的数据”——它描述了存储在表中的实际数据的结构、约束和类型。就像图书馆的卡片目录告诉你去哪里找书但本身不是书一样,tosql_meta 告诉 SQL 生成器如何解释结构体的二进制数据。


关于

本项目为 js0.site ⋅ 重构互联网计划 的开源组件。

我们正在以组件化的方式重新定义互联网的开发范式,欢迎关注: