五、其他的特色: 在第一步开发中实现的还只是只读,很快会有能读写的版本出来。 目前的计划是把数据库对象映射成文件和目录对象。让我们来看看 例子: --8<----------------------------- #建立表 CREATE TABLE invoice ( invoice_id int(10) unsigned NOT NULL auto_increment,
invoice_no int(10) unsigned DEFAULT ’0’ NOT NULL,
payee char(40) DEFAULT ’’ NOT NULL,
PRIMARY KEY (invoice_id),
KEY payee (payee)
);
# 插入数据
INSERT INTO invoice VALUES (1,100,’Company AB’);
INSERT INTO invoice VALUES (2,101,’Company CD’);
INSERT INTO invoice VALUES (3,102,’Company EF’);
--8<-----------------------------
因为 MySQL 没有办法使用记录号,所以我们必须建立主键。
就有了以下的目录结构:
/mountpoint/database/table/primary_key/field
这样,每个列出现在不同的文件行之中,文件树的结构如下:
/mnt/mysql/mydata/invoice/1/invoice_id
/mnt/mysql/mydata/invoice/1/invoice_no
/mnt/mysql/mydata/invoice/1/payee
/mnt/mysql/mydata/invoice/2/invoice_id
/mnt/mysql/mydata/invoice/2/invoice_no
/mnt/mysql/mydata/invoice/2/payee
/mnt/mysql/mydata/invoice/3/invoice_id
/mnt/mysql/mydata/invoice/3/invoice_no
/mnt/mysql/mydata/invoice/3/payee另外,还有第二个办法可以使用: /mountpoint/database/table/.table
和
/mountpoint/database/table/primary_key/.record
/mnt/mysql/mydata/invoice/.table
/mnt/mysql/mydata/invoice/1/.record
/mnt/mysql/mydata/invoice/1/invoice_id
/mnt/mysql/mydata/invoice/1/invoice_no
/mnt/mysql/mydata/invoice/1/payee
/mnt/mysql/mydata/invoice/2/.record
/mnt/mysql/mydata/invoice/2/invoice_id
/mnt/mysql/mydata/invoice/2/invoice_no
/mnt/mysql/mydata/invoice/2/payee
/mnt/mysql/mydata/invoice/3/.record
/mnt/mysql/mydata/invoice/3/invoice_id
/mnt/mysql/mydata/invoice/3/invoice_no
/mnt/mysql/mydata/invoice/3/payee
这些文件是隐含的,以防重复,主要用来方便地通过文本文件
浏览器来查看。
现在,在那些需要使用SQL 语句搜索最小,最大,最后等数据,
可以通过符号连接来实现了:
/mountpoint/database/table/primary_key/.max
或者
/mnt/mysql/mydata/invoice/invoice_id/.max
或者指向
/mountpoint/database/table/field
和
/mnt/mysql/mydata/invoice/3
同样的就可以返回一行的 min/max/sum/avg 等数值。
这能很快并且很容易地实现。
/mnt/mysql/mydata/.keys/
/mnt/mysql/mydata/.keys/invoice_id/
/mnt/mysql/mydata/.keys/payee/
符号连接到主键:
/mnt/mysql/mydata/.keys/.primary_key/
实际上指向
/mnt/mysql/mydata/.keys/invoice_id/
还有一些隐藏文件提供键类型:
/mnt/mysql/mydata/.keys/invoice_id/.type
/mnt/mysql/mydata/.keys/payee/.type
第一个文内容为:¨PRIMARY KEY¨ 第二个为 ¨KEY¨ 。
另外还可以用索引来排序记录,如果读取下面的目录:
/mnt/mysql/mydata/.keys/payee/asc/
PHP 的readdir() 函数就以升序返回数据的符号连接。
另外还有一些全局函数:
/mountpoint/.version
/mountpoint/.last_insert_id
/mountpoint/.uptime
/mountpoint/database/.raid (0/1)
/mountpoint/database/.type (ISAM/MyISAM/HEAP/DBD)
/mountpoint/database/.tables
/mountpoint/database/table/.created
/mountpoint/database/table/.last_updated
/mountpoint/database/table/.last_checked
/mountpoint/database/table/.count |